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

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

문제

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.

올바른 솔루션이 없습니다

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top