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

后端 未结 4 2354
广开言路
广开言路 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:11

    You can also use abort with custom message error:

    from flask import abort
    abort(400, 'My custom message')
    

    See https://flask-restplus.readthedocs.io/en/stable/errors.html

提交回复
热议问题