I want to "ping" the server, check the response of the header to see if the link was broken, and if it is not broken, download the response body.
Traditionally, using the synchronization method with the module requests
, you can send a request get
with a parameter stream = True
and capture the headers before loading the response body, deciding, in case of an error (not found), for example) to interrupt the connection.
My problem is whether to do this using asynchronous libraries grequests
or requests-futures
it has become impossible for my reduced knowledge base.
I tried setting the stream parameter to true in request-futures
, but not using it, it still loads the response body, not letting me interfere as soon as it receives the response headers. And even if that were the case, I would not be sure how to proceed.
Here is what I tried:
test.py
from requests_futures.sessions import FuturesSession
session = FuturesSession()
session.stream = True
future = session.get('http://www.google.com')
response = future.result()
print(response.status_code)
After debugging, I find that it loads the body of the response anyway.
I would appreciate any solution to the original problem, be it my logic or not.
source
share