Search code examples
pythonexceptionflaskwerkzeugdebug-mode

abort(400) raising 500 internal server error - Flask 1.0


I have this function:

if not (payload.get('password') == payload.get('password_cpy')):
        abort(400)

when I run the app with flask run and debug is off, I get a pretty print of a BadRequest error which in raw shows the following info:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<title>400 Bad Request</title>
<h1>Bad Request</h1>
<p>The browser (or proxy) sent a request that this server could not 
understand.</p>

And on terminal I see:

127.0.0.1 - - [30/Apr/2018 00:28:20] "POST /sign_in HTTP/1.1" 400 - 

When I run it and debug is on, the error I get is:

 werkzeug.exceptions.BadRequest
    werkzeug.exceptions.BadRequest: 400 Bad Request: The browser (or proxy) 
    sent a request that this server could not understand.

And in terminal I see a 500 error:

127.0.0.1 - - [30/Apr/2018 00:29:27] "POST /sign_in HTTP/1.1" 500 -

Why do I get two different behaviors? Is there a way in which I can get the 400 error even in debug mode?


Solution

  • try to update your Flask1.0 to Flask1.0.1
    I guess the bug has been fixed in Flask1.0.1 :)

    https://github.com/pallets/flask/issues/2735