I heard that all the 127.x.x.x are loopback IPs. So I try to run Flask on 127.0.0.2 but It gets error "Can't assign requested address" instead. While it works fine on 127.0.0.1
So how can I run flask on 127.0.0.x ?
CodePudding user response:
Maybe what you looking for is to expose flask api on a different host than localhost(127.0.0.1)
You can choose a different port
app.run(host="0.0.0.0", port=8888)
Or host with machine hostname
from socket import gethostname
gethostname()
For custom hostname, add it in /etc/hosts file, it probably already contains a line about 127.0.0.1, in which case you just add your alias to the list
127.0.0.1 localhost localhost.localdomain myappname
in app
app.config['SERVER_NAME'] = 'myappname:5000'
for public, you would need to configure a specific dns
CodePudding user response:
Looks like your OS is a MacOS. MacOS using only 127.0.0.1
for loopback interface
But it is possible to assign 127.0.0.XX
aliases manually
This article has couple completed solutions how to do that