I create requests
POST-requests like this, where I specify timeout threshold:
response = requests.post(url, data=post_fields, timeout=timeout)
However, to determine a "good" threshold value, I would like to benchmark the server response time in advance.
How do I compute the minimum and maximum response times for the server?
The Response
object as returned by requests.post()
has a property called elapsed
, which give the time delta between the Request
was sent and the Response
was received. To get the delta in seconds, use the total_seconds()
method:
response = requests.post(url, data=post_fields, timeout=timeout)
print(response.elapsed.total_seconds())
It should be mentioned that requests.post()
is a synchronous operation, which means that it "blocks" until the response is received.