How do I access the original response headers that contain a redirect when using urllib2.urlopen

StackOverflow https://stackoverflow.com/questions/4953487

Pregunta

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 hay solución correcta

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top