If you initialize the default PyCharm Flask starter project, or just follow the first section that starts up "hello world" or just this:
from flask import Flask
app = Flask(__name__)
@app.route('/')
def hello_world():
return 'Hello World!'
if __name__ == '__main__':
app.run()
you'll have the same code as me. And it works fine, until I change the host
argument to 0.0.0.0
, and then the application starts up like this:
$ python app.py
* Serving Flask app "app" (lazy loading)
* Environment: production
WARNING: This is a development server. Do not use it in a production deployment.
Use a production WSGI server instead.
* Debug mode: off
* Running on http://0.0.0.0:5000/ (Press CTRL+C to quit)
And then when I go to that link, I get an invalid address error:
I need to use 0.0.0.0
instead of 127.0.0.1
because that's the IP address AWS uses for open connections.
How can I even start to get the 0.0.0.0
address to work locally?
I'm working on Windows.
My guess on the question here is a firewall denying the connections or some kind of Windows policy in place and not an IP address problem. Maybe a proxy configured to allow 127.0.0.0/8
but not 0.0.0.0
.
0.0.0.0
is a perfectly valid IP address even for a client. When you bind to it, it simply means listen on all IP addresses configured on the host.
If you are running the browser on the same machine as you are running the Flask app, you can even simply point it to http://0:5000
and it will show the content.
If you are running the application on AWS and are trying to access from a remote machine, than you need to specify the public IP address of your AWS instance instead, since 0.0.0.0
is a non-routable IP address (as any of the reserved private space IP addresses like 10.0.0.0/8
, 127.0.0.0/8
, 192.168.0.0/16
, and 172.16.0.0/12
).