Title: urllib2 redirect to another host doesn't work
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 2.6
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: orsenthil Nosy List: kirax, orsenthil
Priority: normal Keywords: patch

Created on 2010-12-10 12:16 by kirax, last changed 2010-12-24 04:13 by orsenthil. This issue is now closed.

File name Uploaded Description Edit
urllib2.diff kirax, 2010-12-10 12:16
Messages (3)
msg123729 - (view) Author: Kirill Subbotin (kirax) Date: 2010-12-10 12:16
When you open url which redirects to another host (either with 301 or 302), HTTPRedirectHandler keeps "Host" header from the previous request, which leads to a error. Instead a host should be taken from a new location url.

Attached patch is tested with Python 2.6.5.
msg123730 - (view) Author: Senthil Kumaran (orsenthil) * (Python committer) Date: 2010-12-10 12:44
Can you point me to your code and error traceback that was observed and some details about server which gave 301/302 Redirect as what was the hostname and where did it redirect to?

I don't see the code changes that you provided in the patch in the latest versions of urllib, but I am equally surprised if the condition that you said may occur. Because Host will be overridden at some point in time in the Request is made for the new redirected url.

You may want to try with python 2.7 or 2.7.1 too and report if you still face the problem.
msg124590 - (view) Author: Senthil Kumaran (orsenthil) * (Python committer) Date: 2010-12-24 04:13
Closing this as Invalid, because in the latest code, if the Host header is not explicitly specified by the request, then it is added to unredirected headers and if it explicitly specified by the request, then it is taken into account when the redirection happens.

Not sure how the bug reporter's case was.
Date User Action Args
2010-12-24 04:13:26orsenthilsetstatus: open -> closed

messages: + msg124590
resolution: not a bug
stage: resolved
2010-12-10 12:44:20orsenthilsetassignee: orsenthil

messages: + msg123730
nosy: + orsenthil
2010-12-10 12:16:45kiraxcreate