Python3: Is this a bug in urllib?

Johannes Bauer dfnsonfsduifb at
Tue Oct 19 18:47:10 CEST 2010


I've experienced the following behavior with Python3 of which I do not
know if it's a bug or not. On two Python3.1 implementations, Python's
urllib hangs when encountering a HTTP 301 (Redirect).

The code to reproduce is a one-liner (actually, two-liner), Python from
Ubuntu tree:

Python 3.1.2 (r312:79147, Apr 15 2010, 15:35:48)
[GCC 4.4.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from urllib import request; request.URLopener().open("")

Also occurs on another Python version (Gentoo):

Python 3.1.2 (release31-maint, Jun  9 2010, 23:58:21)
[GCC 4.3.4] on linux2

The exchanged HTTP is:

Accept-Encoding: identity
User-Agent: Python-urllib/3.1

HTTP/1.1 301 Moved Permanently
Via: 1.1 IMMPWISA01
Connection: Keep-Alive
Proxy-Connection: Keep-Alive
Content-Length: 218
Expires: Thu, 18 Nov 2010 15:18:40 GMT
Date: Tue, 19 Oct 2010 15:18:40 GMT
Content-Type: text/html; charset=UTF-8
Server: gws
Cache-Control: public, max-age=2592000
X-XSS-Protection: 1; mode=block

<HTML><HEAD><meta http-equiv="content-type"
<H1>301 Moved</H1>
The document has moved
<A HREF="">here</A>.

Although the content might indicate looping forever, it just hangs with
no web traffic whatsoever (the TCP connection stays open, however).

When interrupting with Ctrl-C, this is the calltrace:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python3.1/urllib/", line 1454, in open
    return getattr(self, name)(url)
  File "/usr/lib/python3.1/urllib/", line 1628, in open_http
    return self._open_generic_http(http.client.HTTPConnection, url, data)
  File "/usr/lib/python3.1/urllib/", line 1624, in
    response.status, response.reason, response.msg, data)
  File "/usr/lib/python3.1/urllib/", line 1644, in http_error
    return self.http_error_default(url, fp, errcode, errmsg, headers)
  File "/usr/lib/python3.1/urllib/", line 1648, in
    void =
  File "/usr/lib/python3.1/", line 214, in readinto
    return self._sock.recv_into(b)

Can anyone tell me if this is a bug or expected behavior?


>> Wo hattest Du das Beben nochmal GENAU vorhergesagt?
> Zumindest nicht öffentlich!
Ah, der neueste und bis heute genialste Streich unsere großen
Kosmologen: Die Geheim-Vorhersage.
 - Karl Kaos über Rüdiger Thomas in dsa <hidbv3$om2$1 at>

More information about the Python-list mailing list