AttributeError: 'AppContext' object has no attribute 'expired_jwt'
See original GitHub issueAfter updating from 3.15 to 3.16 or greater, an expired token will throw the following error:
Traceback (most recent call last):
File "/Users/user/path/to/venv/lib/python3.7/site-packages/flask/app.py", line 2309, in __call__
return self.wsgi_app(environ, start_response)
File "/Users/user/path/to/venv/lib/python3.7/site-packages/flask/app.py", line 2295, in wsgi_app
response = self.handle_exception(e)
File "/Users/user/path/to/venv/lib/python3.7/site-packages/flask_cors/extension.py", line 161, in wrapped_function
return cors_after_request(app.make_response(f(*args, **kwargs)))
File "/Users/user/path/to/venv/lib/python3.7/site-packages/flask/app.py", line 1741, in handle_exception
reraise(exc_type, exc_value, tb)
File "/Users/user/path/to/venv/lib/python3.7/site-packages/flask/_compat.py", line 35, in reraise
raise value
File "/Users/user/path/to/venv/lib/python3.7/site-packages/flask/app.py", line 2292, in wsgi_app
response = self.full_dispatch_request()
File "/Users/user/path/to/venv/lib/python3.7/site-packages/flask/app.py", line 1815, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/Users/user/path/to/venv/lib/python3.7/site-packages/flask_cors/extension.py", line 161, in wrapped_function
return cors_after_request(app.make_response(f(*args, **kwargs)))
File "/Users/user/path/to/venv/lib/python3.7/site-packages/flask/app.py", line 1719, in handle_user_exception
return handler(e)
File "/Users/user/path/to/venv/lib/python3.7/site-packages/flask_jwt_extended/jwt_manager.py", line 99, in handle_expired_error
token = ctx_stack.top.expired_jwt
AttributeError: 'AppContext' object has no attribute 'expired_jwt'
@app.errorhandler(ExpiredSignatureError)
def handle_expired_error(e):
try:
token = ctx_stack.top.expired_jwt #<--- explodes here
return self._expired_token_callback(token)
except TypeError:
msg = (
"jwt.expired_token_loader callback now takes the expired token "
"as an additional paramter. Example: expired_callback(token)"
)
warn(msg, DeprecationWarning)
return self._expired_token_callback()
I do not have a custom expired_token_loader so I’m using the default one (default_expired_token_callback)
Issue Analytics
- State:
- Created 5 years ago
- Reactions:1
- Comments:9 (5 by maintainers)
Top Results From Across the Web
FlaskClient object has no attribute 'app_context' - Stack Overflow
1 Answer 1 · We got the same error, RuntimeError: working outside of application context . Also app. · @codyc4321 I edited the...
Read more >'AppContext' object has no attribute in custom Flask extension
**Question:** AttributeError: 'AppContext' object has no attribute ... I'm using Google Proximity Beacon API to interact with beacons' data.
Read more >Create a Flask API with JWT-Based Authentication (Part 1)
Introduction. My goal for this tutorial is to provide a detailed guide to designing and creating a Flask API that uses JSON Web...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

The fix is released in version 3.18.1.
Cheers!
I figured out what was causing my exception, it is a call to the method
decode_tokenon thebefore_requestflask’s hook. This is my minimal, complete, and verifiable example based on the the one from this project docs:After making a request to the
/protectedendpoint, prints:Env:
Dependencies