ross / requests-futures

Asynchronous Python HTTP Requests for Humans using Futures
Other
2.11k stars 152 forks source link

AttributeError: 'Future' object has no attribute 'status_code' #118

Closed Mennaruuk closed 2 years ago

Mennaruuk commented 2 years ago

When using requests-futures to check status codes of websites, I get the following error:

    status_code = response.status_code
AttributeError: 'Future' object has no attribute 'status_code'

Is there a status code attribute?

Thank you.

ross commented 2 years ago

The object returned from .get etc when using requests_futures is the Future object. It's not the actual response, just a thing you can use to retrieve it when you're ready for it. e.g.

future = futures_session.get('https://google.com/')
# some time passes, you do other things, whatever
# this gets the actual response, everything was happening in the background until now, if there was an exception it'll be thrown here.
resp = future.result()
print(resp.status_code)