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: urllib2 raises exception when page redirects to itself
Type: Stage:
Components: Library (Lib) Versions: Python 2.3
process
Status: closed Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: rpijlman
Priority: normal Keywords:

Created on 2005-12-31 16:46 by rpijlman, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (2)
msg27192 - (view) Author: René Pijlman (rpijlman) Date: 2005-12-31 16:46
Some sites redirect a page to itself, due to a
configuration error or bug. The popular browsers seem
to be forgiving: when a URL redirects to itself, they
break the infinite redirect loop and simply display the
page (verified in IE6 and Firefox 1.5).

urllib2.urlopen() raises an exception in the same
situation: HTTP Error 302: The HTTP server returned a
redirect error that would lead to an infinite loop.

Although this message is technically correct, I think
the situation of a page redirecting to itself should be
handled as a special case. It should abort the redirect
and continue with the current request. Users expect
urllib to be able to access sites that popular browsers
can apparently access without problems.

To reproduce (pick a site with this redirect anomaly):

import urllib2
try:
    handle =
urllib2.urlopen('http://www.haselhoff.nl/default.asp')
except IOError,e:
    print str(e)

Reproduced with Python 2.3.5 on Windows XP and Linux.
Also with today's trunk (2.5).
msg27193 - (view) Author: René Pijlman (rpijlman) Date: 2005-12-31 18:10
Logged In: YES 
user_id=1416482

Forget it. I misunderstood. The reason some sites redirect
to the current page itself, is to first set a cookie. 

I retried with cookie support in urllib2 and cookielib in
Python 2.4. With HTTPCookieProcessor installed as opener
urllib2.urlopen worked fine on two different sites that
showed this 'problem'.
History
Date User Action Args
2022-04-11 14:56:14adminsetgithub: 42743
2005-12-31 16:46:15rpijlmancreate