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

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


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


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

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


You can also use abort with custom message error:

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

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