a-luna / flask-api-tutorial

Boilerplate for a Flask REST API with JWT-based authentication, built with SQLAlchemy, Flask-RESTx, PyJWT, and pytest. This is a companion repo for a multi-part tutorial series on my personal website.
https://aaronluna.dev/series/flask-api-tutorial/overview/
74 stars 18 forks source link

Cannot pass test_auth_user_no_token, test_auth_user_expired_token, test_logout_token_blacklisted #14

Closed Cerpint4xt closed 1 year ago

Cerpint4xt commented 1 year ago

All tests uses HTTPStatus.UNAUTHORIZED that uses the decorators.py and exceptions.py where theres an extension of werkzeug.exception Unauthorized and Forbidenn methods, that call a function called get_headers() that according to the test traceback call is getting 3 variables instead of 2.

ERROR flask-api:app.py:1742 Exception on /api/v1/auth/user [GET] Traceback (most recent call last): File "/home/raul/Desktop/flask_api/.tox/py37/lib/python3.7/site-packages/flask/app.py", line 1820, in full_dispatch_request rv = self.dispatch_request() File "/home/raul/Desktop/flask_api/.tox/py37/lib/python3.7/site-packages/flask/app.py", line 1796, in dispatch_request return self.ensure_sync(self.view_functions[rule.endpoint])(view_args) File "/home/raul/Desktop/flask_api/.tox/py37/lib/python3.7/site-packages/flask_restx/api.py", line 404, in wrapper resp = resource(args, kwargs) File "/home/raul/Desktop/flask_api/.tox/py37/lib/python3.7/site-packages/flask/views.py", line 107, in view return current_app.ensure_sync(self.dispatch_request)(kwargs) File "/home/raul/Desktop/flask_api/.tox/py37/lib/python3.7/site-packages/flask_restx/resource.py", line 46, in dispatch_request resp = meth(args, kwargs) File "/home/raul/Desktop/flask_api/.tox/py37/lib/python3.7/site-packages/flask_restx/marshalling.py", line 244, in wrapper resp = f(*args, **kwargs) File "/home/raul/Desktop/flask_api/.tox/py37/lib/python3.7/site-packages/flask_api/api/auth/endpoints.py", line 65, in get return get_logged_in_user() File "/home/raul/Desktop/flask_api/.tox/py37/lib/python3.7/site-packages/flask_api/api/auth/decorators.py", line 15, in decorated token_payload = _check_access_token(admin_only=False) File "/home/raul/Desktop/flask_api/.tox/py37/lib/python3.7/site-packages/flask_api/api/auth/decorators.py", line 48, in _check_access_token error_description=result.error, flask_api.api.exceptions.ApiUnauthorized: 401 Unauthorized: Access token expired. Please log in again.

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/home/raul/Desktop/flask_api/.tox/py37/lib/python3.7/site-packages/flask/app.py", line 2525, in wsgi_app response = self.full_dispatch_request() File "/home/raul/Desktop/flask_api/.tox/py37/lib/python3.7/site-packages/flask/app.py", line 1822, in full_dispatch_request rv = self.handle_user_exception(e) File "/home/raul/Desktop/flask_api/.tox/py37/lib/python3.7/site-packages/flask_cors/extension.py", line 165, in wrapped_function return cors_after_request(app.make_response(f(*args, **kwargs))) File "/home/raul/Desktop/flask_api/.tox/py37/lib/python3.7/site-packages/flask_restx/api.py", line 673, in error_router return original_handler(f) File "/home/raul/Desktop/flask_api/.tox/py37/lib/python3.7/site-packages/flask_restx/api.py", line 671, in error_router return self.handle_error(e) File "/home/raul/Desktop/flask_api/.tox/py37/lib/python3.7/site-packages/flask_restx/api.py", line 721, in handle_error headers = e.get_response().headers File "/home/raul/Desktop/flask_api/.tox/py37/lib/python3.7/site-packages/werkzeug/exceptions.py", line 150, in get_response headers = self.get_headers(environ, scope) TypeError: get_headers() takes 2 positional arguments but 3 were given

Can you please share the requirements.txt or find a work around for this problem? Really learned a lot, but can't continue if no solution here

Cerpint4xt commented 1 year ago

Changing get_headers = self.get_headers(environ, scope=None) will fix the issue