Reputation: 4341
I'm trying to run a flask server on my desktop PC that is publicly available on the internet. I've done the following:
I'm using the following code as a test webserver
from flask import Flask, request, redirect
app = Flask(__name__)
@app.route("/")
def hello_world():
return "Test 123 "
if __name__ == "__main__":
app.run(host="0.0.0.0", port="33")
When I open my browser to: http://192.168.1.11:33/ the page displays properly, I see "Test 123"
My problem comes when trying to connect to my webserver from my public ip address When I open my browser to http://xx.xxx.xxx.xx:30 (my ip address) all I see is "this site can't be reached, xx.xxx.xxx.xx refused to connect"
I've looked up all the stack overflow answers, I've done the following:
screenshot of code running and error shown: https://i.sstatic.net/KTM2G.png
My question is: What do I need to do to make my flask server visible from my public ip address?
Upvotes: 12
Views: 48508
Reputation: 1
Every webservice should be run from different port address.Single service is running from a single port.
Upvotes: 0
Reputation: 191
You must give the public ip address/LAN ip address as an argument to app.run method. When you don't provide host argument, it works fine with http://localhost:8888/ and http://127.0.0.1:888/, but not to access outside the system where you are running the REST services
Following is the example. app.run(host="192.168.0.29",debug=True, port=8888)
Upvotes: 2
Reputation: 1407
You must try and use the same ip of the development server. Thus, for instance, if the dev server is running on a PC with the address 192.168.1.11
and port 33
, other clients must point at the same address: 192.168.1.11:33
.
As far as my small experience, it works with the debugger disabled, but I did not check if this is an essential prerequisite.
good luck
Upvotes: 0
Reputation: 2081
change it to app.run(host= '0.0.0.0', port="33") to run on your machines IP address.
Documented on the Flask site under "Externally Visible Server" on the Quickstart page: http://flask.pocoo.org/docs/0.10/quickstart/#a-minimal-application
Add port forwarding to port 33 in your router Port forwarding explained here http://www.howtogeek.com/66214/how-to-forward-ports-on-your-router/
Upvotes: 4
Reputation: 151
Do you have DHCP activated on your router? If yes do you see your host as 192.168.1.11 in there?
You have to use '0.0.0.0' on host, that tells Flask to listen on all addresses.
Try specifying the port with quotes as app.run(host="0.0.0.0", port="33")
Upvotes: 10