下面的函数出现以下错误。如果我删除jwt_required,它确实有效,所以我猜CORS允许访问。可能是什么问题?
@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:UsersedAppDataRoamingPythonPython38site-packagesflaskapp.py", line 2088, in __call__
return self.wsgi_app(environ, start_response)
File "C:UsersedAppDataRoamingPythonPython38site-packagesflaskapp.py", line 2073, in wsgi_app
response = self.handle_exception(e)
File "C:UsersedAppDataRoamingPythonPython38site-packagesflask_corsextension.py", line 165, in wrapped_function
return cors_after_request(app.make_response(f(*args, **kwargs)))
File "C:UsersedAppDataRoamingPythonPython38site-packagesflaskapp.py", line 2070, in wsgi_app
response = self.full_dispatch_request()
File "C:UsersedAppDataRoamingPythonPython38site-packagesflaskapp.py", line 1515, in full_dispatch_request
rv = self.handle_user_exception(e)
File "C:UsersedAppDataRoamingPythonPython38site-packagesflask_corsextension.py", line 165, in wrapped_function
return cors_after_request(app.make_response(f(*args, **kwargs)))
File "C:UsersedAppDataRoamingPythonPython38site-packagesflaskapp.py", line 1513, in full_dispatch_request
rv = self.dispatch_request()
File "C:UsersedAppDataRoamingPythonPython38site-packagesflaskapp.py", line 1499, in dispatch_request
return self.ensure_sync(self.view_functions[rule.endpoint])(**req.view_args)
File "C:UsersedAppDataRoamingPythonPython38site-packagesflask_corsdecorator.py", line 128, in wrapped_function
resp = make_response(f(*args, **kwargs))
TypeError: wrapper() missing 1 required positional argument: 'fn'
我假设您使用的是flask-jwt-extended
>CCD_ 2。一个突破性的改变是将所有视图装饰器移到一个单独的装饰器,这是一个返回装饰器的可调用对象。因此,需要括号。尝试使用jwt_required()