rcknr
rcknr

Reputation: 355

Getting error headers with urllib2

I need to send a PUT request to a web service and get some data out of error headers that is the expected result of the request. The code goes like this:

Request = urllib2.Request(destination_url, headers=headers)
Request.get_method = lambda: 'PUT'

try:
   Response = urllib2.urlopen(Request)
except urllib2.HTTPError, e:
   print 'Error code: ', e.code
   print e.read()

I get Error 308 but response is empty and I'm not getting any data out of HTTPError. Is there a way to get HTTP headers while getting an HTTP error?

Upvotes: 3

Views: 2315

Answers (1)

phihag
phihag

Reputation: 287885

e has undocumented headers and hdrs properties that contains the HTTP headers sent by the server.

By the way, 308 is not a valid HTTP status code.

Upvotes: 7

Related Questions