如何解决这个“NotImplementedError” Windows 上的 urllib2 / gevent 错误?
我正在尝试在 Windows XP 上使用用 gevent 修补的 urllib2 打开一个 url:
from gevent import monkey
monkey.patch_all()
import urllib2
opener = urllib2.build_opener()
request = urllib2.Request("http://www.google.com")
response = opener.open(request)
并且在 opener.open
调用期间遇到此异常:
File "C:\Python26\lib\site-packages\gevent\socket.py", line 768, in getaddrinfo
sockaddr = (inet_ntop(AF_INET6, res), port, 0, 0)
File "C:\Python26\lib\site-packages\gevent\socket.py", line 133, in inet_ntop
raise NotImplementedError('inet_ntop() is not available on this platform')
NotImplementedError: inet_ntop() is not available on this platform
<SERPScrapper at 0xbc0f60> failed with NotImplementedError
查看 gevent socket.py 源代码,它似乎是相关的Windows 上的 IPV6...
有解决这个问题的想法或建议吗?
编辑:我没有遇到其他网址的问题(即:http://www.bing .com)。看来google正在使用IPV6。有没有办法强制 IPV4 响应?
I'm trying to open an url with urllib2 patched with gevent on Windows XP:
from gevent import monkey
monkey.patch_all()
import urllib2
opener = urllib2.build_opener()
request = urllib2.Request("http://www.google.com")
response = opener.open(request)
And I get this exception during the opener.open
call:
File "C:\Python26\lib\site-packages\gevent\socket.py", line 768, in getaddrinfo
sockaddr = (inet_ntop(AF_INET6, res), port, 0, 0)
File "C:\Python26\lib\site-packages\gevent\socket.py", line 133, in inet_ntop
raise NotImplementedError('inet_ntop() is not available on this platform')
NotImplementedError: inet_ntop() is not available on this platform
<SERPScrapper at 0xbc0f60> failed with NotImplementedError
Looking at the gevent socket.py source code it seems to be related to IPV6 on windows...
Any idea or proposition to solve this problem ?
edit: I don't get the problem with other url (ie: http://www.bing.com). It seems that google is using IPV6. Is there a way to force an IPV4 response ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试改为向
http://ipv4.google.com/
发出请求。Try making your request to
http://ipv4.google.com/
instead.