IOError 35 when trying to read the result of call to urllib2.urlopen

M

matt

I'm using urllib2's urlopen function to post to a service which should
return a rather lengthy JSON object as the body of its response.
Here's the code:

{{{
ctype, body = encode_multipart(fields, files)
url = 'http://someservice:8080/path/to/resource'
headers = {'Content-Type': ctype, 'Content-Length': str(len(body))}
req = urllib2.Request(url, body, headers)
resp = urllib2.urlopen(req)

resp_body = resp.read()
}}}

When I try to look at "resp_body" I get this error:

IOError: [Errno 35] Resource temporarily unavailable

I posted to the same URI using curl and it worked fine, so I don't
think it has to do with the server.

Any thoughts?
 
S

Steven D'Aprano

matt said:
When I try to look at "resp_body" I get this error:

IOError: [Errno 35] Resource temporarily unavailable

I posted to the same URI using curl and it worked fine, so I don't
think it has to do with the server.

Are your Python code and curl both using the same proxy? It may be that one
is going direct and the other is using a proxy.

Or perhaps the destination is just flaky, and the resource genuinely is
temporarily unavailable. Or it doesn't like your useragent string and is
lying.
 
M

matt

matt said:
When I try to look at "resp_body" I get this error:
IOError: [Errno 35] Resource temporarily unavailable
I posted to the same URI using curl and it worked fine, so I don't
think it has to do with the server.

Are your Python code and curl both using the same proxy? It may be that one
is going direct and the other is using a proxy.

Or perhaps the destination is just flaky, and the resource genuinely is
temporarily unavailable. Or it doesn't like your useragent string and is
lying.

No proxy. It's all local over the loopback interface (probably should
have mentioned that). The service I'm POSTing to is a Python web app
with CherryPy as the framework. Also, because of some dependency
issues I'm using Python 2.6.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,189
Latest member
CryptoTaxSoftware

Latest Threads

Top