I am working on a Python Flask application in Ubuntu under VirtualBox, run from OSX. Now I want to connect my python application from OSX (the host OS). I am using a NAT networking, and already read about Port Forwarding (which I think it's very easy). But, somehow if I test my application using Google Chrome, try to open http://localhost:8888 (my server in Ubuntu listen to port 8888), chrome return with Server return no response (or kinda)
I have issue the following command in OSX terminal : `VBoxManage modifyvm "Ubuntu 12.0.4 LTS" --natpf1 "fikrposdc,tcp,,8888,,8888". And my python application already listening to port 8888, :
* Running on http://127.0.0.1:8888
I've read that in Ubuntu, by default there is no firewall. So, I try to netstat, but issuing `netstat | grep LISTEN didn't gave any output...
Is there something that I missed?
`
Wooops!
Having read related question, I found this question with the exact same problem. And I modify my code to run the application :
app.run(host="0.0.0.0", port=8888)
Now I can continue my work!
Thanks
Related
I have two computers in the same enterprise network. The one with Windows XP (IP 192.168.101.96) and the other with Windows 7 (IP 192.168.101.98).
If I start Django project on PC with Windows XP (python manage.py runserver 192.168.101.96:8001), I can easily access it from Windows 7 PC with browser.
But the opposite way doesn't work. If I start Django project on PC with Windows 7, I can't access it from Windows XP PC.
The same situation is with command python -m SimpleHTTPServer 8001.
I tried to add a rule for external connections on TCP port 8001 in Windows firewall settings. Also I tried to add python.exe to firewall exceptions, but nothing seems to work...
It should be noted that when I start Django server and execute NETSTAT -p tcp -ano command, I can see line:
TCP 192.168.101.98:8001 0.0.0.0:0 LISTENING 6920
But nevertheless, nothing work. What can be the source of the problem?
for access to another computer server , server must be run on port 80.
you must run django server on port 80
python manage.py runserver 0.0.0.0:80
then access with type ip in the browser without post number :
http://192.168.101.98/
good luck
The problem was in ESET Endpoint Security special firewall. It's "automatic mode" blocks traffic without any promt to user. The problem can be solved by adding special rule to this firewall or changing it's main policy to "interactive mode" for example.
I was setting up a public Ipython Notebook in my remote Ubuntu 12.04 server according to http://ipython.org/ipython-doc/1/interactive/public_server.html#notebook-public-server, but when all was done, I cannot connect to it via both chrome and safari (in both https and http modes), I got timeout error in chrome, safari told me server isn't responding. So I tested the system by setting up following simple python server:
python -m SimpleHTTPServer
And the same error occured. I also checked the port with sudo netstat -anltp|grep :8000, which seems fine:
tcp 0 0 0.0.0.0:8000 0.0.0.0:* LISTEN 22683/python
What surprises me is that I have the apache running and holding websites just fine (I also try to turn it off when configuring python server but that didn't help). Can anyone give me a clue what might be wrong in the Ubuntu server and how I should debug it?
I have found the issue: it turns out that the ports are closed by firewall, although in netstat it says python is listening to port 8000, but when incoming request reaches port 8000 it is rejected before getting to python server. By opening the ports the issue can be well resolved.
It turns out that the ports are closed by firewall, although in netstat it says python is listening to port 8000, but when incoming request reaches port 8000 it is rejected before getting to python server. By opening the ports the issue can be well resolved.
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.
We have developed an app in python and are using flask to expose its api via http requests.
all this on WINDOWS -
Everything works ok and we have tested in-house with no problems and we are now trying to use the app in the real world - we have gotten our IT dept to give us a public facing ip/port address (forwarded through a firewall ??) and now we can't access the server/app at all.
After a bit of digging, we've found the problem has something to do with the Windows Firewall configuration, when its on it won't work, when its off everything is fine.
the flask app code is run like so: app.run(debug=False, host='0.0.0.0', port=8080)
the port 8080 is setup in the Firewall Exceptions as is python.exe in the Program Exceptions
netstat -a shows the app is sitting there awaiting connection.
If I try to access the site though chrome I get the error: ERR_CONNECTION_TIMED_OUT.
With the firewall on i'm never seeing any "hits" come through to the app at all.
Is there some other configuration I'm missing?
Many thanks.
When running Flask from a windows machine with a firewall I open a port with the following commands:
netsh firewall add portopening TCP 8080 "MyAppName"
netsh advfirewall firewall add rule name="MyAppName TCP Port 8080" dir=in action=allow protocol=TCP localport=8080
netsh advfirewall firewall add rule name="MyAppName TCP Port 8080" dir=out action=allow protocol=TCP localport=8080
It work for me. Is it too much? I don't know as I am not a Firewall guru :(
When running as a service the program running the service is not python.exe but rather pythonservice.exe. You will have to add that to the allowed programs in the Windows Firewall Setup. In my case it is located under C:\Python33\Lib\site-packages\win32\pythonservice.exe.
I'm trying to set up an ipython notebook server on an Ubuntu host machine - but can't seem to access it remotely. I set up the notebook server as per the tutorial, and launch it - everything seems fine. But going to https://my-host-ip:9999/ I get a timeout (error 118) message in the browser.
My intuition is that need to open the appropriate port (9999 in the setup tutorial) on my host. How do I do this (safely) with Ubuntu? More generally, is there a debugging checklist I should go through at this point?
Did you try to run it as public ? (listening on '*' ?)
http://ipython.org/ipython-doc/dev/interactive/htmlnotebook.html#running-a-public-notebook-server
Don't forget to make it over https and with password.
Is the port 9999 open?
I don't know why, but I had to set the IP to the IP of host to make it work.