Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
275 views
in Technique[技术] by (71.8m points)

python - Flask debug=True does not work when going through uWSGI

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()
question from:https://stackoverflow.com/questions/10364854/flask-debug-true-does-not-work-when-going-through-uwsgi

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.

You see 502 because flask/werkzeug do not send any data to the webserver, so nginx will returns a 502.

You can emulate the debugger using --catch-exceptions option in uWSGI (but please do not do it in production)

So, the reason you're seeing 502s will be because of that. The fix would be to add --catch-exceptions to uWSGI on execution.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...