import grequests
import time
start_time = time.time()
sites = ['https://facebook.com' for x in range(5)]
data = {'a': 'b'}
responses = [grequests.get(u, data=data) for u in sites]
for response in responses:
print(response)
print(f'{response.text}')
print("--- %s seconds ---" % (time.time() - start_time))
When I try to get data by the .text method, I have an error:
AttributeError: 'AsyncRequest' object has no attribute 'text'
Even If I try to get status_code I have the same error with missing the attribute
The command to fix that I've searched pip3 install --upgrade gevent==1.1rc3 returning me an error: fatal error: Python.h: No such file or directory into 5 | #include "Python.h"
When module use async then it may run code in separated thread and it doesn't wait for result but it gives you object which you can later use to check if there is already result. In some modules you may use
awaitto wait for result (but this works only insideasyncfunction and it needs to runasyncloop) but some modules have special functions to wait for results.And
grequestshas also special function for this - which you should see in official examplesIf you use it then you get list of objects
<Response>. Withoutmap()you get only list of objects<grequests.AsyncRequest>Minimal working example: