Flask - Cannot Connect on port 5000

Connection Refused

When you start your Flask app you might find when trying to connect from a remote machine that it doesn’t work. The first thing is to check firewalls, both locally and further out e.g. AWS.

Perhaps when using nginx as a reverse proxy you might see the following error:

[error] 9#0: *47 connect() failed (111: Connection refused) while connecting to upstream, client: xxx.xxx.xx.xxx, server: example.org, request: "POST /my_endpoint HTTP/1.1", upstream: "", host: "yy.yy.yy.yy"


If that all seems fine, then you might need to specify the host argument to the app:

python my_app.py --host=

or, just add it to your code:

if __name__ == '__main__':
    app.run(host='', threaded=True, debug=True)

Hopefully that helps. If not, let me know