我使用Flask并且更精确地使用错误处理程序中止。我可以使用make_response自定义使用我的错误发送的消息。我还使用Blueprints来注册错误处理程序。
在今天之前,一切都很好。但是今天事情变得糟糕,不可能再定制我的信息了。
对于我的例子,我采取401错误,我尝试发送消息“自定义消息”
我的错误处理程序401
@errors.app_errorhandler(401)
def access_denied(error):
# if the description have the message attribute
if 'message' in error.description:
return make_response(jsonify(
{
'error': error.description['message']
}
), 401)
else:
return make_response(jsonify(
{
'error': 'Access Denied'
}
), 401)
我在__init__.py中的蓝图注册
from app.errors.ErrorHandler import errors
app.register_blueprint(errors)
我的中止电话
from flask import abort
abort(
401,
{
'message': 'custom message'
}
)
错误401由我的处理程序处理,但发送的消息是默认消息“访问被拒绝”。
我坚持说:昨天一切顺利! (2019年3月19日 - 下午6点)也许这是一个没有记录的错误或改进
感谢您的帮助,如果您需要更多信息,请随时提出
路易
问题来自werkzeug模块:https://github.com/pallets/werkzeug/issues/1483
现在修好了