ipython notebook server setup debug - python

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.

Related

find available port to run server

What's the best approach in python to do something like what happens when you run jupyter notebook, in other words, run a server (for example, with http.server) on some available port if the default one isn't available? Is it common to just catch the error if starting the server fails and try a different port until it works?
You can use port 0 - this will bind your server to some port that is currently known to be available by kernel. However, that makes a problem of service discovery - how your clients will know which port number server is listening on? If that's only you, shouldn't be big deal.

How to run Liclipse/Pydev debugger over internet?

I have a remote development Linux machine (with own IP address) in a VPS provider. I also have my machine that connects to internet via a router. I want a Django process in the server to connect to a pydev debug server on my machine.
I use pydev debugger, this configuration tells django at any host to connect to the given host/port where the debugger is running.
pydevd.settrace('localhost', port=5678, suspend=False)
How to connect to the VPS from my desktop? NAT is impossible since the router and DHCP is not in my control. VPN seems feasible but complicated.
I think the best way to resolve it in this case would be doing a port forwarding through ssh -- I don't have any specific instructions for that, but google has plenty ;)

Can't connect to Flask web service, connection refused

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.

python, django, vagrant and access error on windows host machine

Well, I'm trying to access a python server (for django development) in a Virtual Box VM via vagrant, but I can't connect with it in my windows browsers. I'll try to describe all the things I've done to make this work, so maybe it can help you guys.
My configurations:
I set my vagrant file to allow connections in port 8000 (guest and host)
I have disabled my windows firewall.
I have turned off the firewall on the VM
I have disabled all chrome extensions (including addblock)
I have disabled almost all apps in my windows to minimize the chances that some program could use port 8000
I have unchecked "automatically detect settings" and "use a proxy server for your lan" in the lan settings (windows internet options), then done the ip /release, ip /renew and rebooted my machine
Yes, the python server is running well on the vm
I tried the default 127.0.0.1:8000 (no success) and changed to 0.0.0.0:8000 using the command "python manage.py runserver 0.0.0.0:8000", but still ... :(
I have a nginx server in the vm running well for my php apps in port 80, and i cant access them with no problems
I use pycharm for python development and it starts my server normally in the vm either using 127.0.0.1:8000 or 0.0.0.0:8000
I think that's it, but the error persists, I can't access my python server in my ip 192.168.56.101 in port 8000, this ip is my private network on the vm that runs good with nginx.
But the result is always the same
Whenever I try access http://192.168.56.101:8000/ all my browsers (IE, Firefox, Chrome) cannot complete the request, in Chrome the error is ERR_CONNECTION_TIMED_OUT
Thanks in advance for any help !
My problem was the firewall rules. I dont really need it since its a development environment, so I delete all the rules in /etc/iptables/rules.v4 and save the file. That solve it all. Tks.

how do i configure python/flask for public access with windows firewall

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.

Categories

Resources