How to intentionally cause a 400 Bad Request in Python/Flask?

后端 未结 4 2324
广开言路
广开言路 2021-02-19 00:18

A consumer of my REST API says that on occasion I am returning a 400 Bad Request - The request sent by the client was syntactically incorrect. error.

4条回答
  •  醉梦人生
    2021-02-19 00:54

    You can use abort to raise an HTTP error by status code.

    from flask import abort
    @app.route('/badrequest400')
    def bad_request():
        abort(400)
    

提交回复
热议问题