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).
|