Python urllib2.urlopen () hanging with local connection to Java Restlet server

I am trying to connect to a local running Restlet server with python, but the connection hangs endlessly (or disconnects if I set a timeout).

import urllib2 handle = urllib2.urlopen("http://localhost:8182/contact/123") # hangs 

If I use curl from the shell to open the above URL, the results are returned quickly. If I use urllib2 to open another local service (e.g. Django web server on port 8000), urllib2 works fine.

I tried disabling the firewall (I do this on OS X). I tried changing localhost to 127.0.0.1. The logs from Restlet for connecting curl and urllib2 look the same away from the user agent.

My workaround would be to just call curl via subprocess , but I would better understand why this is not working.

Here's what my Restlet resource looks like:

 public class ContactResource extends ServerResource { @Get public String represent() throws Exception { return "<contact details>"; } //.... } 

Let me know if you want more info / code

+8
java python curl urllib2 restlet
source share
2 answers

I ran into similar problems and ended up using query packages .

+3
source share

there is a ProxyHandler ( http://docs.python.org/library/urllib2.html#urllib2.ProxyHandler ) in urllib2

try passing an empty dictionary to it before urlopen

 urllib2.ProxyHandler([]) handle = urllib2.urlopen("http://localhost:8182/contact/123") 
0
source share

All Articles