How to measure server response time for Python requests POST-request

The Response object returned by requests.post() (and requests.get() etc.) has a property called elapsed, which provides 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())

Note that requests.post() is a synchronous operation, which means that it blocks until the Response is received.

Leave a Comment