所以我正在关注烧瓶 jwt 扩展https://flask-jwt-extended.readthedocs.io/en/stable/basic_usage/的基本用法。我的代码在下面,基本上每次我向端点发送请求时,我都会收到一个关于返回变量无效的奇怪错误,我不知道发生了什么。我尝试只返回一个随机字符串,如“success”,但即使这样也没有用。奇怪的是,当我删除 @jwt_required 时,代码正常工作,这让我觉得烧瓶 jwt 扩展有问题。让我们来看看:
端点:
@api.route('/auth_test/', methods = ['GET'])
class auth_test(Resource):
@api.response(200, 'user found')
@api.response(404, 'user not found')
@api.response(400, 'Invalid parameters')
@cross_origin(origin='*')
@jwt_required
def get(self):
current_user = get_jwt_identity()
return jsonify(logged_in_as=current_user), 200
卷曲请求:
curl -X GET http://127.0.0.1:5000/auth_test/ -H "Accept: application/json" -H "Authorization:Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyEiUnR9ilHk1QoJjm5obxmtV2v9c"
回复:
TypeError: 'auth_test' object is not callable
The view function did not return a valid response. The return type must be a string, dict, tuple, Response instance, or WSGI callable, but it was a function.