urllib2.urlopen broken?

Mike Meyer mwm at mired.org
Wed Jun 6 15:55:58 EDT 2007


In <18023.2281.63362.844051 at bhuda.mired.org>, Mike Meyer <mwm at mired.org> typed:
> In 2.5.1 (and 2.[45], but not 2.3):

Sigh. Sorry 'bout that. Since I started it, the breakage is:

Python 2.5.1 (r251:54863, May 15 2007, 15:31:37) 
[GCC 3.4.6 [FreeBSD] 20060305] on freebsd6
Type "help", "copyright", "credits" or "license" for more information.
>>> import urllib2
>>> u = urllib2.urlopen('http://www.mired.org/')
>>> u.fileno()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/opt/lib/python2.5/socket.py", line 252, in fileno
    return self._sock.fileno()
AttributeError: HTTPResponse instance has no attribute 'fileno'

The problem is that urlib2 was changed to wrap an HTTPResponse object
in a socket._fileobject to get a few more file methods. Except (as
reported above) HTTPResponse doesn't have a fileno() method, so when
_fileobject tries to use it, it blows up.

Adding an appropriate method to HTTPResponse:

  def fileno(self):
      return self.fp.fileno()

fixes the problem, but may not be the best solution. If no one
suggests a better one, I'll file the appropriate bug report.

	<mike
-- 
Mike Meyer <mwm at mired.org>		http://www.mired.org/consulting.html
Independent Network/Unix/Perforce consultant, email for more information.



More information about the Python-list mailing list