-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy paththousandEyes_auth.py
More file actions
28 lines (23 loc) · 873 Bytes
/
thousandEyes_auth.py
File metadata and controls
28 lines (23 loc) · 873 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import requests
import json
import urllib3
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
import time
from pprint import pprint
import credentials
def get_data(uri):
while True:
url = f"https://api.thousandeyes.com{uri}"
headers = {"Authorization": "Bearer "+credentials.thousandEyes_token}
response = requests.get(url, headers=headers, params={"format":"json"}, verify=False)
if response.status_code == 200:
return response.json()
elif(response.status_code == 429):
print("got response 429 from ThousandEyes, retrying in 60 seconds..")
time.sleep(60)
continue
else:
print(response, response.text)
raise Exception("Failed to get data")
if __name__ == "__main__":
pprint(get_data(uri="/v6/web/http-server/3732333"))