Question

I'm trying to parse the location header of an HTTP response that is returned after using urllib2.urlopen, but the only response headers that I receive are from the target redirect --- not the original response that contains the location header.

I have followed other questions on Stack Overflow that suggest to subclass the urllib2.HTTPRedirectHandler, but I'm still not able to understand how to access the original response that urlopen ends up following.

Here's an example of the problem:

import urllib2

req = urllib2.urlopen("http://wp.me")

print req.info()

The output of print contains the response headers of the target of the redirected request. I would like to see the original.

Any help would be appreciated.

No correct solution

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top