Issue
My macbook and windows desktop are on the same wifi network.
Here is the python 3 code I run on my Mac (myFlask.py):
from flask import Flask
app = Flask(__name__)
@app.route("/")
def hello():
return "Hello from Mac"
pn = 5000
ip = "192.168.1.146"
if __name__ == '__main__':
app.run(host = ip,port=pn)
When I run this on mac, and I can enter 192.168.1.146:5000 as a url on the browser on both devices and see "Hello from Mac"
Here is the python 3 code I run on my Desktop (myFlask.py):
from flask import Flask
app = Flask(__name__)
@app.route("/")
def hello():
return "Hello from Windows"
pn = 5000
ip = "192.168.1.105"
if __name__ == '__main__':
app.run(host = ip,port=pn)
The problem: When I run this on the windows desktop, and when I enter 192.168.1.105:5000 as a url on the browser on both device, I see "Hello from Windows" on the desktop, but "This site can’t be reached" on the mac.
I tried the following:
- I double checked the IP addresses, and 192.168.1.105 is the correct one (ipv4). I also tried all the other IP addresses from ipconfig on the windows command line, but still no luck.
- I took a look at externally visible server at http://flask.pocoo.org/docs/0.12/quickstart/ and tried to do $python3 myFlask.py --host=0.0.0.0 No luck here.
- I checked to see if DHCP is enabled in my router (Linksys) and yes it is enabled.
- I turned on all sharing settings on Home, Public, and Domain in the control panel at windows.
- I turned off the FireWall settings.
Even after all this, neither my mac nor my android phone nor my iphone nor my other mac can find the flask server hosted on the windows desktop. But all my other devices (including windows desktop) can see the flask server hosted by the mac.
What should I do?
Solution
This gets into the vagaries of networking. Change to
ip = '0.0.0.0'
and try again. When you tried to pass --port=0.0.0.0
to your app, the option was ignored, since your app isn't parsing options. The flask
runner does parse them. On the Mac side, the invocation would be
FLASK_APP=myApp.py flask run --host=0.0.0.0
I don't know what the equivalent would be on Windows.
Answered By - Dave W. Smith
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.