Lately I've been playing with Python to discover its potential and I've just stumbled upon SimpleHTTPServer.
I'm on Windows 10.
I run:
python -m SimpleHTTPServer
the output is:
Serving HTTP on 0.0.0.0 port 8000 ...
I've opened the browser both on smartphone and tablet, but none of them can connect to the server when I type "http://127.0.0.1:8000".
(Translating from italian, maybe is not the exact translation)
iPad: "Safari can't open the page because the server has stopped responding"
Android: "WebPage does not respond. the webpage may be temporarily not available or it could have been moved to another address"
Why does it not work? How do I fix this?
Maybe your firewall is blocking access to python based server
Try this:
Open windows firewall
click on "allow an app or feature..." on the left side of the opened window
search for python in the list and check both the boxes private and public
It should work now
127.0.0.1 is always the IP address of the local system (its associated hostname is "localhost"). In other words, if you type 127.0.0.1:8000 on your tablet or Android device, the browser on that device will try to connect to a server running on the same device, listening on port 8000. You'll need to find out the IP address of the computer you're running Python on, and type that instead. You can use the ifconfig command on Unix, or ipconfig on Windows.
Related
I created a dummy website using Django, python, HTML, CSS, and JavaScript recently. After completing it I tested the website by starting the server.
python3 manage.py runserver
I was able to open the website in a browser in the local machine using the link 127.0.0.1:8000/
Now, I want to connect to this server using my android device.
As my first step I started a hotspot on my android which I've connected my pc by wifi in order to bring the client and server in the same network.
Then I figured out the local IP address of my PC and I've switched off the firewall on my PC.
After doing that I ran the Django runserver command with this address,
python3 manage.py runserver 0.0.0.0:8000
And just like before I am able to use the website without a problem in my local machine/PC. However, when I tried to connect to this with my mobile using the link,
192.168.45.220:8000
Where 192.168.45.220 is the IP address of the PC which I'm running as the current local server. I get a error message as
The site can't be reached
127.0.0.1 refused to connect
ERR_CONNECTION_REFUSED
I don't understand what I am doing wrong. Can someone let me know what I could do to fix this?
Thanks.
You need to use the IP address of your computer in your local network (assuming your mobile device is on the same network as your desktop). On Linux and Mac you can check your IP with ifconfig or using ipconfig on Windows. localhost always refers to the current machine, i.e. localhost on your desktop points to your desktop and on your mobile device it points to your mobile device. That's why you can't access it - the app runs on your desktop not mobile.
Once you know the IP address of your computer you need to replace localhost with it. In my case the IP is 192.168.1.10 so I use the following address to access my app:
http://192.168.1.10:8000/
1.Type in cmd (windows): ipconfig
2.Look for IP address IPV4:
3. Type in URL search bar of your browser (example): 192.168.1.4:3000 3000 is the port number that your react app is running on:
4.Make sure that your mobile browser (Chrome is preferred) is on the latest update, my react app didn't load up for me because chrome wasn't updated.
I'm trying to run a simple web server on a Raspberry Pi with Flask. When I run my Flask app, it says:
running on http://127.0.0.1:5000/
But when I enter this address on my laptop's in Chrome, I get
ERR_CONNECTION_REFUSED
I can open 127.0.0.1:5000 on the Raspberry Pi's browser. What do I need to do to connect from another computer?
Run your app like this:
if __name__ == '__main__':
app.run(host='0.0.0.0')
It will make the server externally visible. If the IP address of the machine is 192.168.X.X then, from the same network you can access it in 5000 port. Like, http://192.168.X.X:5000
when you are running the server via flask run change it to flask run --host=0.0.0.0
to connect, find the IPV4 address of the server that your script is running on. On the same network, go to http://[IPV4 address]:5000
A reason could also be in firewall refusing incoming connections on port 5000. Try:
sudo ufw allow 5000
app.run(host='0.0.0.0',port=5000)
if you run your app in this way then your server will be visible externally.
Steps by Setp:
Run your app by using the following command
app.run(host='0.0.0.0',port=5000)
Go to the window cmd . Type ipconfig and get the get the IPV4 adress suppose your IPV4 address is 192.168.X.X
Go to the mobile browser and type the 192.168.X.X:5000
If you have debug = True inside your app.run(), then it will not be visible to other machines either. Specify host and port inside app.run() without the debug = True.
You will have to run the development server such that it listens to requests on all interfaces and not just the local one
Ask Flask to listen on 0.0.0.0:PORT_NUMBER
or any other port you may choose
On MacOS 12.4 (Monterey) I couldn't load localhost nor my local IP but it worked with both of these:
0.0.0.0
127.0.0.1
Just change the URL in the browser if it loads with "localhost".
Both devices must be connected to same network.
Use app.run(host='0.0.0.0',port=5000) and run with your own Ipv4
address like his http://[Your Ipv4 address]:5000
If you are connecting this with android app then don't forget to
put INTERNET permission in manifest file.
Contrary to popular believe 127.0.0.1 is not the same a localhost.
I solved the issue above by setting 127.0.0.1 explicitly on both ends.
Well i was also here to know answer but i guess i found out problem. The reason is that you may not activated or run flask that's why it is showing error. For that you have to start from terminal "flask run" and then surely your flask will run...
The issue may occur, if VPN is on, so try to switch it off.
I want to set up a Django development server that both my computers and smart phones can access whilst on my network via wifi.
I've already set up a development server that my computer can access on http://127.0.0.1:8000/. However, my other devices can't.
The Django documentation says:
"Note that the default IP address, 127.0.0.1, is not accessible from other machines on your network. To make your development server viewable to other machines on the network, use its own IP address (e.g. 192.168.2.1) or 0.0.0.0 or :: (with IPv6 enabled)."
I've found my "public IP address" and tried to use this by:
python manage.py runserver xx.xx.xxx.x (where this is my public ip address) but i get a "Command error: 'xx.xx.xxx.x' is not a valid port number or address:port pair."
I then tried the same with :8000 after the IP address, but got an error "Error: That IP address can't be assigned to".
Then python manage.py runserver 0.0.0.0:8000. The command line reports "Starting development server at ...", but when i try "http://0.0.0.0:8000/" on Chrome, i get a "This site can't be reached error".
Is it something to do with my windows firewall settings?
Please can you someone help me? Thanks!
This is very late, but I run onto an additional issue following this post. If you are using a rhel distro based and if firewalld
is enabled it might be blocking the connection. So for testing purposes run:
systemctl stop firewalld
0.0.0.0 is not a real address, it's a placeholder that just says that the server is not bound to a specific IP.
If you run on 127.0.0.1, it will only answer to queries that where addressed to 127.0.0.1, so localhost only.
Using your private address (192.168.0.x most often), it will only answer to queries to this address (so opening with the 127.0.0.1 should not work, but sometime does depending on the implementation)
So, if you use 0.0.0.0, it will answer to anything.
tl;dr : use 0.0.0.0 and connect using :
127.0.0.1 from this computer
your computer's private ip address for other computers inside your lan
you public IP for computers outside your lan. Note that this will require additional configuration on your router
You will need your local ip address not public.
You can get the local ip in windows machine by typing the following command in cmd : ipconfig .
On Linux type the following in terminal : ifconfig
The ip address will be of the form 192.168.0.101[Example]
So in your phone's browser type : 192.168.0.101:8000
I try to setup a simple webinterface with cherrypy & python.
The page is visible over localhost:8080. If I try a different computer on the same LAN and try to connect with it via 192.168.1.100:8080 it doesn't work however. Do I need to open some ports? I thought this would not be needed with linux.
OS: Ubuntu on both systems
Tried Browsers Chrome & midori
Make sure to bind your server to 0.0.0.0:8080 instead of localhost:8080.
localhost always resolves to the loopback interface, which is only reachable from the same host.
0.0.0.0 on the other hand means "all interfaces" (also known as INADDR_ANY).
For details read up about INADDR_LOOPBACK and INADDR_ANY in the ip(7) manpage.
I'm have an issue with running the built in Python server that comes with 3.1, this may or may not be an issue with Python, in fact it probably isn't.
I start my server in the correct directory with "python -m http.server 8000" as the documentation suggests (http://docs.python.org/release/3.1.3/library/http.server.html).
When I navigate to that port on my local network with another computer using the url 192.168.2.104:8000 (my local ip and the port) my page loads. When I use my global IP, however, it stops working. Port 8000 is forwarded correctly. I used www.yougetsignal.com to verify that port 8000 was open using my global IP. Why in the world would Chrome be saying "Oops! Google Chrome could not connect to [REDACTED]:8000" then? Other server applications (such as my Minecraft server) work just fine. Is there something I'm missing? Furthermore, why would yougetsignal connect to my port but not Chrome?
With most routers ports are only mapped when someone connects from the outside (internet/WAN). You're testing it from your LAN so basically you're connecting to your router when you use your public IP. Ask a friend to test, i.e. from an outside connection.