Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting AttributeError while importing grequests in Python 3.4

I've been trying to use grequests for asyncronous HTTP requests in my Python project, however I got an AttribteError and have been searching for solution for hours.

Here's my testing code:

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)

And the error message:

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'

I've tried to uninstall and re-install both grequests and the whole Python, however the problem still exists.

I also tried to avoid using grequest (and use gevent), but the same problem happened.

After some search, I believe the closest problem I can find is this one:

python3: socket._fileobject removed #434

But it seems not very trivial for me, and the solution provided is for SSL-related stuff.

If you have any solution or similar problem please share, thank you very much!

like image 532
Mori Nakamura Avatar asked Mar 30 '26 16:03

Mori Nakamura


1 Answers

I encountered the same problem. After

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

the code executed without problems (--user is optional).

like image 140
J.J. Hakala Avatar answered Apr 02 '26 12:04

J.J. Hakala



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!