简体   繁体   English

Python Flask - Abort - 自定义错误消息不再起作用

[英]Python Flask - Abort - Custom error message does not working anymore

I use Flask and more precisely abort with an error handler . 我使用Flask并且更精确地使用错误处理程序 中止 I can custom the message sent with my error by using make_response . 我可以使用make_response 自定义使用我的错误发送的消息 I also use Blueprints to register the error handler. 我还使用Blueprints来注册错误处理程序。

Before today, everything were fine. 在今天之前,一切都很好。 But things go bad today and it is impossible to custom my message anymore. 但是今天事情变得糟糕,不可能再定制我的信息了。

For my example, I take the 401 error and I try to send the message "custom message" 对于我的例子,我采取401错误,我尝试发送消息“自定义消息”

My handler for error 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)

My blueprint registration in __init__.py 我在__init__.py中的蓝图注册

from app.errors.ErrorHandler import errors
app.register_blueprint(errors)

My abort call 我的中止电话

from flask import abort
abort(
      401,
      {
           'message': 'custom message'
      }
)

The error 401 is handled by my handler but the message sent is the default message 'Access Denied'. 错误401由我的处理程序处理,但发送的消息是默认消息“访问被拒绝”。

I insist : Everything worked yesterday ! 我坚持说:昨天一切顺利! (19 March 2019 - 6pm) Maybe it is a bug or an improvement not documented at all (2019年3月19日 - 下午6点)也许这是一个没有记录的错误或改进

Thank you for your help and if you need more information, feel free to ask 感谢您的帮助,如果您需要更多信息,请随时提出

Louis 路易

The problem was from the werkzeug module : https://github.com/pallets/werkzeug/issues/1483 问题来自werkzeug模块: https//github.com/pallets/werkzeug/issues/1483

It is fixed now 现在修好了

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM