I call app.run(debug=True)
in my flask file.
and I have it deployed with uWSGI and nginx (I followed these instructions)
uwsgi -s /tmp/uwsgi.sock -w flask_file_name:app -H /path/to/virtual/env --chmod-socket 666
But when I get an error, I don't get any debug information in the browser or in the uWSGI log.
Any ideas?
flask_file_name.py:
from flask import Flask, make_response, Response, jsonify
import json
app = Flask(__name__)
app.debug = True
@app.route("/")
def hello():
return "Hello World!"
if __name__ == '__main__':
app.run()
The problem is
uwsgi
does not callapp.run()
. It callsapp()
. So instead you can do this:According to the Flask mailing list you cannot use Flask's debug option with
uWSGI
, because it's not to be used in a forking environment.So, the reason you're seeing 502s will be because of that. The fix would be to add
--catch-exceptions
touWSGI
on execution.For me it only worked after I combined the two answers above like this:
This question is old, but I'll post this for future reference...
If you want to get the werkzeug error page to work with uwsgi, try using werkzeug's
DebuggedApplication
middleware:That should do the trick but DO NOT FORGET to do this ONLY in development environments.