在 Python 3.4 中导入 grequest 时出现 AttributeError

Getting AttributeError while importing grequests in Python 3.4

我一直在尝试在我的 Python 项目中使用 grequests 进行异步 HTTP 请求,但是我得到了一个 AttribteError 并且一直在寻找解决方案几个小时。

这是我的测试代码:

import grequests

urls = ['htt://google.com', 'http://yahoo.com', 'http://bing.com']
unsent_request = (grequests.get(url) for url in urls)
results = grequests.map(unsent_request)
print(results)

错误信息:

Traceback (most recent call last):
    File "<censored>", line 1, in <module>
        import grequests
    File "C:\Python34\lib\site-packages\grequests.py", line 21, in <module>
        curious_george.patch_all(thread=False, select=False)
    File "C:\Python34\lib\site-packages\gevent\monkey.py", line 195, in patch_all
        patch_socket(dns=dns, aggressive=aggressive)
    File "C:\Python34\lib\site-packages\gevent\monkey.py", line 124, in patch_socket
        from gevent import socket
    File "C:\Python34\lib\site-packages\gevent\socket.py", line 119, in <module>
        _fileobject = __socket__._fileobject
AttributeError: 'module' object has no attribute '_fileobject'

我已经尝试卸载并重新安装 grequests 和整个 Python,但问题仍然存在。

我也尝试避免使用grequest(并使用gevent),但同样的问题发生了。

经过一番搜索,我相信我能找到的最接近的问题是这个:

python3: socket._fileobject removed #434

但这对我来说似乎不是很简单,提供的解决方案是针对 SSL 相关的东西。

如有解决方法或类似问题请分享,万分感谢!

我遇到了同样的问题。

之后
pip3 install --user --upgrade gevent==1.1rc3

代码执行没有问题(--user 是可选的)。