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

后端 未结 4 2332
广开言路
广开言路 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 01:20

    you can return the status code as a second parameter of the return, see example below

    @app.route('/my400')
    def my400():
        code = 400
        msg = 'my message'
        return msg, code
    

提交回复
热议问题