user3580316
user3580316

Reputation:

Python requests measure response time

I am trying to measure the response time of a website but I am getting errors.

Script:

#!/usr/bin/python

import requests

time= requests.get("http://google.com").elapsed.total_seconds()

print time

Error:

Traceback (most recent call last):
  File "./test.py", line 5, in <module>
    time= requests.get("http://google.com").elapsed.total_seconds()
AttributeError: 'Response' object has no attribute 'elapsed'

Upvotes: 2

Views: 8219

Answers (1)

alecxe
alecxe

Reputation: 473873

.elapsed attribute was introduced in requests 1.2.0 (changelog). Update the package:

pip install --upgrade requests

Upvotes: 4

Related Questions