小编Flo*_*yer的帖子

获取HTTP的urllib2.urlopen返回值的套接字

我正在尝试使用urllib2进行文件的异步下载,但没有成功找到套接字(或其fileno)以等待HTTP请求的新数据.这是我已经尝试过的.

>>> from urllib2 import urlopen
>>> from select import select
>>> r = urlopen('http://stackoverflow.com/')
>>> select([r], [], [])
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python2.6/socket.py", line 307, in fileno
    return self._sock.fileno()
AttributeError: HTTPResponse instance has no attribute 'fileno'
>>> r.fileno()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python2.6/socket.py", line 307, in fileno
    return self._sock.fileno()
AttributeError: HTTPResponse instance has no attribute 'fileno'
>>> r.fp.fileno()
Traceback (most recent call last): …
Run Code Online (Sandbox Code Playgroud)

python urllib urllib2

5
推荐指数
1
解决办法
2246
查看次数

标签 统计

python ×1

urllib ×1

urllib2 ×1