4

When my deployed Flask application has an error, I only see a standard error message in the browser.

Internal Server Error

The server encountered an internal error and was unable to complete your request. Either the server is overloaded or there is an error in the application.

Going through the logs to find the error is inconvenient. How can I output the error to the browser instead?

davidism
  • 121,510
  • 29
  • 395
  • 339
Ivan
  • 107
  • 1
  • 7
  • set debug=True in app.run(debug=True) or in your configurations. Remember to set it back for production. – syntonym Jun 07 '16 at 14:42
  • where i can write this, im write in init.py if __name__ == "__main__": app.run(debug=True) But error not display when im go to the site on VPS ubuntu – Ivan Jun 07 '16 at 15:18
  • 1
    Are you using the development server or a separate WSGI server? If the latter, you if evaluates to false, so you'd need to see debug elsewhere. – dirn Jun 07 '16 at 15:20
  • @Ivan Please show the contents of your `__init__.py` file. – arrakis_sun Jun 07 '16 at 16:03
  • You should add `app.config['DEBUG'] = True` to your `__init__.py` file, outside the `if name == "main": ...` block. – arrakis_sun Jun 07 '16 at 16:05

1 Answers1

0

For debugging purposes you may try this:

import traceback   

@app.errorhandler(Exception)
def handle_500(e=None):
    app.logger.error(traceback.format_exc())
    return 'Internal server error occured', 500
davidism
  • 121,510
  • 29
  • 395
  • 339
arrakis_sun
  • 556
  • 3
  • 8
  • thx. its ok, but now request return Status Code:200 OK with error, but must be 500 – Ivan Jun 07 '16 at 15:20
  • im have error,only if im deploy on ubuntu, on ,y loacl machine its working good – Ivan Jun 07 '16 at 15:29
  • im write in init.py if name == "main": app.run(debug=True) But error not display when im go to the site on VPS ubuntu – Ivan Jun 07 '16 at 15:32
  • why is method bad?im use app.run(debug=True) But error not print in response on my VPS ubuntu server – Ivan Jun 07 '16 at 15:48
  • How i can print error on my site, if this method bad? – Ivan Jun 07 '16 at 15:49