[ python-Bugs-1394453 ] urllib2 raises exception when page redirects to itself

SourceForge.net noreply at sourceforge.net
Sat Dec 31 19:10:31 CET 2005


Bugs item #1394453, was opened at 2005-12-31 17:46
Message generated for change (Comment added) made by rpijlman
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1394453&group_id=5470

Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: Python Library
Group: Python 2.3
Status: Open
Resolution: None
Priority: 5
Submitted By: René Pijlman (rpijlman)
Assigned to: Nobody/Anonymous (nobody)
Summary: urllib2 raises exception when page redirects to itself

Initial Comment:
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).

----------------------------------------------------------------------

>Comment By: René Pijlman (rpijlman)
Date: 2005-12-31 19:10

Message:
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'.

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1394453&group_id=5470


More information about the Python-bugs-list mailing list