-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathauth_tokens.py
More file actions
35 lines (26 loc) · 1021 Bytes
/
auth_tokens.py
File metadata and controls
35 lines (26 loc) · 1021 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
29
30
31
32
33
34
35
import requests
from config import MASTER_URLS
def fetch_auth_tokens():
auth_tokens = {}
headers = {'Accept': 'application/json',
'Content-Type': 'application/x-www-form-urlencoded'
}
data = {
'username': 'myuser',
'password': '1234',
'eauth': 'auto'
}
for master, base_url in MASTER_URLS.items():
login_url = f"{base_url}/login"
try:
response = requests.post(login_url, headers=headers, data=data, verify=False)
response.raise_for_status() # Raises an HTTPError for bad responses
auth_token = response.json().get('return', [{}])[0].get('token', 'No token retrieved')
auth_tokens[master] = auth_token
except requests.exceptions.RequestException as e:
print(f"Failed to get auth token for {master}")
auth_tokens[master] = 'Failed to get auth token'
return auth_tokens
if __name__ == '__main__':
tokens = fetch_auth_tokens()
print(tokens)