Flask listens only on 127.0.0.1 ignoring host parameter

Valentin Heinitz picture Valentin Heinitz · Jul 11, 2014 · Viewed 10k times · Source

I'm using Flask on Windows 7. Flask and related versions are below:

Flask==0.10.1
Werkzeug==0.9.3

Accessing the app from the same computer is OK using http://127.0.0.1:5000 However from another computer in LAN the access fails: http://192.168.101.103:5000

I start the app with these parameters:

#app.py
if __name__ == '__main__':
    app.run( host='0.0.0.0:5000')

One thing I don't understand is, when I start netcat on the same computer, where Flask is currently listening on the same port, it works, and netcat is even accessible from another computer:

>c:\Python27\python manage.py runserver
>
 * Running on http://127.0.0.1:5000/
 * Restarting with reloader

works ...

>nc -l -p 5000

works on the same computer, same port ???

GET / HTTP/1.1
Accept: text/html, application/xhtml+xml, */*
Accept-Language: de-DE
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0;

Accept-Encoding: gzip, deflate
Host: 192.168.101.103:5000
DNT: 1
Connection: Keep-Alive

even accepting connection from another computer ???

So beside the obvious question, how to get Flask serving for LAN, I'm curious, how could two processes of one machine listen on the same port?

Thank you!

Answer

Andy picture Andy · Jul 11, 2014

The port goes in it's own parameter:

app.run(
    host="0.0.0.0",
    port=5000
)