-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEncodedSolution.py
More file actions
27 lines (22 loc) · 795 Bytes
/
EncodedSolution.py
File metadata and controls
27 lines (22 loc) · 795 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
import requests
import requests
from requests.auth import HTTPBasicAuth
import base64
import time
url = "urlasdefined in api documentation"
#the token is generated by encoding login:password in Base 64
print("----TOKEN----")
login = 'loginapiname'
password = 'apipassword'
token = login+":"+password
print("Token:", base64.b64encode(token.encode("ascii")).decode("ascii"))
print()
#Once the token is generated, you can use the token directly in your code, it is safer in case your code leaks.
# print("----SOLUTION 1----")
headers = {
'Authorization': 'Basic xxxgeneratedtockenxxx'
}
response = requests.get(url, headers=headers)
print(response.text)
print()
time.sleep(2) #just because I do 2 API requests in a row, Sigfox limits to 1 request per second, so I need to slow my strict dow