Click here to Skip to main content
15,888,286 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi forum,

there is a python program using flask and socket.io to create a web server which runs on my development machine. On the same machine, I can access the server and get the website it serves by typing localhost:5000 in the address field of my browser.
This site should also be accessible from other devices in our LAN (including WiFi). So It should serve to its IP address. I type 192.168.1.42 in the address field of the same browser on the same machine that worked with localhost. And it fails.

[Edit]
Failing means that Firefox displays a cartoon of baby Godzilla with a power plug and matching reception that he just unplugged (?)
The text reads (my translation from German):
"Error: Connection failed.
Firefox cannot establish a connection to the server under 192.168.1.42:5000.
o The website might temporarily be unavailable. Please try again later
o If you also cannot reach other web sites, check your network or internet connection.
o If your computer or network is protected by a proxy or firewall, ensure that Firefox is allowed to access the internet"
[/Edit]
I created a firewall rule, even deactivated the firewall altogether, but to no avail. That doesn't seem to be my problem.

I'm on Windows 10 Prof x64, python 3.8.2, Flask 1.1.2, Flask-SocketIO 4.3.2, if that matters.

How do I get access to the running web server from locations in our LAN other than localhost?

What I have tried:

+ Created a firewall rule for port 5000
+ Deactivated firewall
+ Started the SocketIO application with parameter
Python
socketio.run(app, host="192.168.1.42:5000")

[Edit]
+ Other parameter
Python
socketio.run(app, host="192.168.1.42:5000", cors_allowed_origins='*')
[/Edit]
[Edit2]
+ Other ip address
Python
socketio.run(app, host="0.0.0.0:5000", cors_allowed_origins='*')
[/Edit2]

[Edit3]
My problem definitely comes from the application, not the system.
Proof: I didn't start my application, but
$ winpty python -m http.server 5000
instead, checked with firefox on the same machine to open the url 192.168.1.42 and also from an Android phone in the same LAN. Both work flawlessly (get access to the very directory python has been started in).
[/Edit3]
Posted
Updated 18-Mar-21 21:23pm
v6
Comments
Richard MacCutchan 10-Mar-21 4:48am    
What actually happens when you try to connect?
lukeer 11-Mar-21 3:52am    
I updated the question.
Richard MacCutchan 11-Mar-21 4:13am    
I have just tried something similar on my home system and it works fine. There must be an issue with your network or addresses.
lukeer 11-Mar-21 7:04am    
It seems so. I also tried with the above "everyone allowed" approach, but Firefox keeps stating the same error message.

Are there network/os/computer settings that every web developer knows are important, just not me noob?
Richard MacCutchan 11-Mar-21 7:57am    
Sorry, but I have no suggestions; my network settings are as set by Windows.

My webserver is Microsoft's IIS and I have not set anything special in the configuration. The web pages are in the standard location. I access the pages on this system (the server) via localhost/URLpage, and from other PC (iPad and Android phone) via 192.168.1.4/URLpage, i.e. the local WiFi IP address.

1 solution

In an attempt to find out how other web servers on the same machine would be treated, I started
command
$ winpty python -m http.server 5000
(Found that somwhere in the internet). That triggered the firewall to tell that it had just blocked python.exe and ask if it should continue doing so, which I negated. This python-based web server worked well. And from that time on, the flask-socket.io web server did as well.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900