Flask server not visible from my public ip address
Solution 1
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")
Solution 2
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/
Solution 3
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)
Keatinge
Updated on November 12, 2020Comments
-
Keatinge over 3 years
I'm trying to run a flask server on my desktop PC that is publicly available on the internet. I've done the following:
- Set up a static IP address: 192.168.1.11 (http://i.imgur.com/Z9GEBYV.png)
- Forwarded port 33 on my router to my static ip address (http://i.imgur.com/KGNQ2Qk.png)
- Setup flask to use my static ip and port: 33
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:
- Turned off windows firewall
- Changed host from "192.168.1.11" to "0.0.0.0"
- Tried a different port
screenshot of code running and error shown: http://i.imgur.com/a05GvEs.png
My question is: What do I need to do to make my flask server visible from my public ip address?
-
Keatinge about 8 yearsI switched the port to "33", same problem. As for the DCHP, my host wasn't on there before, but I added it now. I still am experiencing the same problem. (This site can't be reached) Here's a screenshot of my router's DCHP page, maybe you can see some problem I don't. i.imgur.com/kkv07MI.png
-
Keatinge about 8 yearsI have done both of these, just tested again right now. I still cannot connect. My port is 100% forwarded, tested online. i.imgur.com/uZISBqI.png
-
Keatinge about 8 yearsFrom a mobile phone disconnected from wifi.
-
ganeshredcobra about 8 years@Racialz So you are using mobile data for internet connection and in browser you are trying public ip:33 are you trying this way?
-
alexdlaird about 4 yearsEven simpler, use
pyngrok
(pip install pyngrok
) to invoke and managengrok
right from within yourserver.py
. Here's a full Flask example, but basically you'd just need tofrom pyngrok import ngrok
and thenngrok.connect(5000)
when you're defining the routes. -
zabop over 2 yearsFirst link broken.