Issue 1520831: urrlib2 max_redirections=0 disables redirects (original) (raw)

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:18 admin set github: 43650
2010-11-20 21:03:28 jjlee set messages: +
2010-11-20 17:54:12 orsenthil set messages: +
2010-11-15 20:55:30 jjlee set messages: +
2010-11-15 11:31:11 orsenthil set messages: +
2010-11-13 15:31:06 jjlee set messages: +
2010-11-13 12:25:45 orsenthil set status: open -> closednosy: - BreamoreBoymessages: + resolution: wont fixstage: test needed -> resolved
2010-10-18 10:11:22 orsenthil set assignee: orsenthil
2010-09-12 10:48:22 BreamoreBoy set nosy: + BreamoreBoymessages: + versions: + Python 3.2, - Python 2.7
2009-02-13 02:08:47 ajaksu2 set nosy: + jjlee
2009-02-12 17:39:44 ajaksu2 set nosy: + ajaksu2, orsenthilstage: test neededmessages: + versions: + Python 2.7
2006-07-11 22:16:22 rus_r_orange create