This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: urrlib2 max_redirections=0 disables redirects
Type: enhancement Stage: resolved
Components: Library (Lib) Versions: Python 3.2
process
Status: closed Resolution: wont fix
Dependencies: Superseder:
Assigned To: orsenthil Nosy List: ajaksu2, jjlee, orsenthil, rus_r_orange
Priority: normal Keywords:

Created on 2006-07-11 22:16 by rus_r_orange, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (9)
msg60939 - (view) Author: rus_r_orange (rus_r_orange) Date: 2006-07-11 22:16
When using urllib2, I wanted to be able to see all
redirects that come back from an http server. I set the
variable max_redirections in HTTPRedirectHandler to 0.
However, redirects were still being followed because
the req didn't have a redirect_dict set.

IMHO, if max_redirections is set to 0, redirects should
not be followed, no matter what. 

For my personal situation, I copied urllib2 and hacked
it to that if max_redirections is 0 (or less), it will
always raise the HTTPError that is associated with the
status code received by the request.

I saw this issue on WinXP with 2.4.1 and on Linux with
2.4.3.
msg81785 - (view) Author: Daniel Diniz (ajaksu2) * (Python triager) Date: 2009-02-12 17:39
rus_r_orange: Can you share your patch and tests?
msg116168 - (view) Author: Mark Lawrence (BreamoreBoy) * Date: 2010-09-12 10:48
Senthil/John has this simply slipped under the radar?
msg121131 - (view) Author: Senthil Kumaran (orsenthil) * (Python committer) Date: 2010-11-13 12:25
This is an invalid bug report at the moment. In fact, aged.
The redirection depends upon max_redirections and max_repeats together. Setting it to 0 explicitly (inside the code) is not a good use case under any condition.
msg121141 - (view) Author: John J Lee (jjlee) Date: 2010-11-13 15:31
Why not?
msg121222 - (view) Author: Senthil Kumaran (orsenthil) * (Python committer) Date: 2010-11-15 11:31
John, I was trying to find out what does rfc say on "Client Ignoring the 30X REDIRECT headers". There is no point made on Client's trying to ignore it, instead it said that it should follow the Redirect and must not endlessly loop.

Setting max_redirect to 0 is similar to ignoring the redirect request , which I found to be a bad idea under any case.

Also, if one has to just see redirect urls coming from http server, it can be done by subclassing the HTTPRedirectHandler and logging the redirects.
msg121241 - (view) Author: John J Lee (jjlee) Date: 2010-11-15 20:55
That's silly.  A justification of the need for a new feature isn't needed, because this is already-implemented feature that simply does the wrong thing at the edge case.

It's not high priority, but it is a bug.
msg121696 - (view) Author: Senthil Kumaran (orsenthil) * (Python committer) Date: 2010-11-20 17:54
What should it do? OP expected that it print the redirected url. I don't think that's helpful by setting max_redirections to 0, when it can be achieved in other ways. 

Also, max_redirections is not exposed (as a parameter or arg) or a documented, how do we define user's expectation when he tries to change it?
msg121775 - (view) Author: John J Lee (jjlee) Date: 2010-11-20 21:03
Oops, I hadn't noticed that max_redirections isn't part of the API.  In that case, I agree that it's not strictly a bug.  I'd also agree it's not very important.

FWIW: "want[ing] to see all redirects" is not the same thing as printing URLs -- I assume he simply meant that he wanted .open to return the original response, and not a redirected response.  I don't think he meant that he wanted urllib2 itself to allow him to literally see the URLs on his screen, by printing them to stdout (!).
History
Date User Action Args
2022-04-11 14:56:18adminsetgithub: 43650
2010-11-20 21:03:28jjleesetmessages: + msg121775
2010-11-20 17:54:12orsenthilsetmessages: + msg121696
2010-11-15 20:55:30jjleesetmessages: + msg121241
2010-11-15 11:31:11orsenthilsetmessages: + msg121222
2010-11-13 15:31:06jjleesetmessages: + msg121141
2010-11-13 12:25:45orsenthilsetstatus: open -> closed

nosy: - BreamoreBoy
messages: + msg121131

resolution: wont fix
stage: test needed -> resolved
2010-10-18 10:11:22orsenthilsetassignee: orsenthil
2010-09-12 10:48:22BreamoreBoysetnosy: + BreamoreBoy

messages: + msg116168
versions: + Python 3.2, - Python 2.7
2009-02-13 02:08:47ajaksu2setnosy: + jjlee
2009-02-12 17:39:44ajaksu2setnosy: + ajaksu2, orsenthil
stage: test needed
messages: + msg81785
versions: + Python 2.7
2006-07-11 22:16:22rus_r_orangecreate