Tutorial :urllib.urlopen to open page on same port just hangs



Question:

I am trying to use urllib.urlopen to open a web page running on the same host and port as the page I am loading it from and it is just hanging.

For example I have a page at: "http://mydevserver.com:8001/readpage.html" and I have the following code in it:

data = urllib.urlopen("http://mydevserver.com:8001/testpage.html")  

When I try and load the page it just hangs. However if I move the testpage.html script to a different port on the same host it works fine. e.g.

data = urllib.urlopen("http://mydevserver.com:8002/testpage.html")  

Does anyone know why this might be and how I can solve the problem?


Solution:1

A firewall perhaps? Try opening the page from the command line with wget/curl (assuming you're on Linux) or on the browser, with both ports on settings. Furthermore, you could try a packet sniffer to find out what's going on and where the connection gets stuck. Also, if testpage.html is dynamically generated, see if it is hit, check webserver logs if the request shows up there.


Solution:2

Maybe something is already running on port 8001. Does the page open properly with a browser?


Solution:3

You seem to be implying that you are accessing a web page that is scripted in Python. That implies that the Python script is handling the incoming connections, which could mean that since it's already handling the urllib call, it is not available to handle the connection that results from it as well.

Show the code (or tell us what software) you're using to serve these Python scripts.


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »