Ocassional 503 when calling /.well-known/jwks.json (flask-api sdk)

I’m running into a weird issue where 90% of the time auth0 works as expected, but occasionally (and more so recently) I get a

HTTP Error 503: Service Temporarily Unavailable

when calling


Eg yesterday I had a flood of these errors between 4pm - 6pm and 8pm-10pm UTC.

I have 2 questions:

  1. Is this a problem on my side or auth0 side?
  2. If this is a known problem on auth0 side, what are the implications for the user? I can’t reproduce the error because it’s so infrequent, so I don’t know if UX is damaged in any way… and so I don’t know how to handle in code.

The code I’m using is pretty much word for word the flask-api sdk.

Full error trace:

HTTPError: HTTP Error 503: Service Temporarily Unavailable
  File "flask/app.py", line 2447, in wsgi_app
    response = self.full_dispatch_request()
  File "flask/app.py", line 1952, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "flask_cors/extension.py", line 165, in wrapped_function
    return cors_after_request(app.make_response(f(*args, **kwargs)))
  File "flask/app.py", line 1821, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "flask/_compat.py", line 39, in reraise
    raise value
  File "flask/app.py", line 1950, in full_dispatch_request
    rv = self.dispatch_request()
  File "flask/app.py", line 1936, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "gpu_back/misc/auth0_.py", line 114, in decorated
    payload = decode_jwt(token)
  File "gpu_back/misc/auth0_.py", line 47, in decode_jwt
    jsonurl = urlopen("https://" + AUTH0_DOMAIN + "/.well-known/jwks.json")
  File "urllib/request.py", line 222, in urlopen
    return opener.open(url, data, timeout)
  File "urllib/request.py", line 531, in open
    response = meth(req, response)
  File "urllib/request.py", line 640, in http_response
    response = self.parent.error(
  File "urllib/request.py", line 569, in error
    return self._call_chain(*args)
  File "urllib/request.py", line 502, in _call_chain
    result = func(*args)
  File "urllib/request.py", line 649, in http_error_default
    raise HTTPError(req.full_url, code, msg, hdrs, fp)

Extra info:

  • Which SDK this is regarding: e.g. flask-api
  • SDK Version: where do I find it? I’ve looked everywhere. It’s the current version at the time of posting.
  • Platform Version: Python 3.8, Flask 1.1.2
  • Code Snippets/Error Messages/Supporting Details/Screenshots: (above)


Couldn’t find the edit button…

Sorry I should clarify my second question. What are the implications for my backend code? Like if I get this error should I just retry 10x and one of the requests is likely to go through? Or what’s the recommended course of action?

One solution I thought of:

def recursively_fetch_url(max_tries, current_try=1):
        jsonurl = urlopen("https://" + AUTH0_DOMAIN + "/.well-known/jwks.json")
        jwks = json.loads(jsonurl.read())
        return jwks
        if current_try < max_tries:
            return recursively_fetch_url(max_tries, current_try+1)
    print('auth0 failed to decode jwt!')