Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting error headers with urllib2

Tags:

python

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?

like image 370
rcknr Avatar asked May 31 '26 13:05

rcknr


1 Answers

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.

like image 52
phihag Avatar answered Jun 03 '26 02:06

phihag



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!