I am having the following error from the below function. If I remove jwt_required, it does work, so I am guessing CORS is allowing access. What could be the issue?
@app.route('/user_authentication/protected', methods=['POST'])
@cross_origin(headers=['Content-Type','Authorization'])
@jwt_required
def protected():
# username = get_jwt_identity()
username = "sana ne "
# response send to Vue page
response = {}
response['user'] = username
print(response)
return jsonify(response), 200
127.0.0.1 - - [08/Sep/2022 07:40:30] "POST /user_authentication/protected HTTP/1.1" 500 -
Traceback (most recent call last):
File "C:\Users\ed\AppData\Roaming\Python\Python38\site-packages\flask\app.py", line 2088, in __call__
return self.wsgi_app(environ, start_response)
File "C:\Users\ed\AppData\Roaming\Python\Python38\site-packages\flask\app.py", line 2073, in wsgi_app
response = self.handle_exception(e)
File "C:\Users\ed\AppData\Roaming\Python\Python38\site-packages\flask_cors\extension.py", line 165, in wrapped_function
return cors_after_request(app.make_response(f(*args, **kwargs)))
File "C:\Users\ed\AppData\Roaming\Python\Python38\site-packages\flask\app.py", line 2070, in wsgi_app
response = self.full_dispatch_request()
File "C:\Users\ed\AppData\Roaming\Python\Python38\site-packages\flask\app.py", line 1515, in full_dispatch_request
rv = self.handle_user_exception(e)
File "C:\Users\ed\AppData\Roaming\Python\Python38\site-packages\flask_cors\extension.py", line 165, in wrapped_function
return cors_after_request(app.make_response(f(*args, **kwargs)))
File "C:\Users\ed\AppData\Roaming\Python\Python38\site-packages\flask\app.py", line 1513, in full_dispatch_request
rv = self.dispatch_request()
File "C:\Users\ed\AppData\Roaming\Python\Python38\site-packages\flask\app.py", line 1499, in dispatch_request
return self.ensure_sync(self.view_functions[rule.endpoint])(**req.view_args)
File "C:\Users\ed\AppData\Roaming\Python\Python38\site-packages\flask_cors\decorator.py", line 128, in wrapped_function
resp = make_response(f(*args, **kwargs))
TypeError: wrapper() missing 1 required positional argument: 'fn'
I am assuming you are using flask-jwt-extended
> v4.0.0
. One breaking change was to move all view decorators to a single decorator, which is a callable that returns a decorator. For this reason brackets are required. Try using jwt_required()