urllib2.urlopen()によって返されたファイルのようなオブジェクトをポーリングしようとしているときに、http://bugs.python.org/issue1327971に記載されているバグに遭遇しました。urllib2.urlopen()によって返されたファイルのようなオブジェクトでpollを使用していますか?
残念ながら、Pythonには比較的新しいので、実際には、問題を回避する方法を決定することはできません。ここで
は、エラーがスローされます私のコードの蒸留バージョンです:
import urllib2, select
if __name__ == "__main__":
p = select.poll()
url = "http://localhost/"
fd = urllib2.urlopen(url)
p.register(fd, select.POLLIN | select.POLLERR | select.POLLHUP | select.POLLNVAL)
result = p.poll()
for fd, event in result:
if event == select.POLLIN:
while 1:
buf = fd.read(4096)
if not buf:
break
print buf
そして私は、Python 2.6上で実行するときに発生するエラー:
Traceback (most recent call last):
File "/home/shab/py/test.py", line 9, in <module>
p.register(fd, select.POLLIN | select.POLLERR | select.POLLHUP | select.POLLNVAL)
File "/usr/lib/python2.6/socket.py", line 287, in fileno
return self._sock.fileno()
AttributeError: HTTPResponse instance has no attribute 'fileno'
アップデート:私はしないでくださいシステムライブラリを変更したい。