[ python-Bugs-1327971 ] HTTPResponse instance has no attribute 'fileno'

SourceForge.net noreply at sourceforge.net
Sun Oct 16 17:23:13 CEST 2005


Bugs item #1327971, was opened at 2005-10-16 10:41
Message generated for change (Comment added) made by kevindication
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1327971&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: None
Group: None
Status: Open
Resolution: None
Priority: 5
Submitted By: Kevin Dwyer (kevindication)
Assigned to: Nobody/Anonymous (nobody)
Summary: HTTPResponse instance has no attribute 'fileno'

Initial Comment:
In python2.3, the following code works.  In python2.4
it fails with an AttributeError:

>>> import urllib2
>>> request = urllib2.Request("http://pheared.net")
>>> opener = urllib2.build_opener()
>>> r = opener.open(request)
>>> r.fileno()
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
  File "/usr/lib/python2.4/socket.py", line 246, in fileno
    return self._sock.fileno()
AttributeError: HTTPResponse instance has no attribute
'fileno'

Without a fileno it's hard to do things like select.

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

>Comment By: Kevin Dwyer (kevindication)
Date: 2005-10-16 11:23

Message:
Logged In: YES 
user_id=285914

Actually that's not entirely correct.  The fix is probably
more like the other hack in there:

--- urllib2.py-orig     2005-10-16 11:19:34.000000000 -0400
+++ urllib2.py  2005-10-16 11:22:30.000000000 -0400
@@ -1007,6 +1007,7 @@
         # out of socket._fileobject() and into a base class.

         r.recv = r.read
+        r.fileno = r.fp.fileno
         fp = socket._fileobject(r)

         resp = addinfourl(fp, r.msg, req.get_full_url())


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

Comment By: Kevin Dwyer (kevindication)
Date: 2005-10-16 11:08

Message:
Logged In: YES 
user_id=285914

I think the problem is at line 1010 in urllib2.py.

--- urllib2.py-orig     2005-10-16 11:04:30.000000000 -0400
+++ urllib2.py  2005-10-16 11:05:02.000000000 -0400
@@ -1007,7 +1007,7 @@
         # out of socket._fileobject() and into a base class.

         r.recv = r.read
-        fp = socket._fileobject(r)
+        fp = socket._fileobject(r.fp)

         resp = addinfourl(fp, r.msg, req.get_full_url())
         resp.code = r.status



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

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


More information about the Python-bugs-list mailing list