-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathcharts.py
More file actions
22 lines (16 loc) · 873 Bytes
/
charts.py
File metadata and controls
22 lines (16 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
import requests
def get(hostname, port, did, limit):
loginHeaders = {'Authorization': 'Basic cG9sYXJpc19jbGllbnQ6cG9sYXJpcw==', 'Content-Type' : 'application/x-www-form-urlencoded'}
loginData = {'grant_type':'password', 'scope':'write', 'username':'polaris', 'password':'polaris'}
loginUrl = "http://" + hostname + ":" + port + "/oauth/token"
res = requests.post(loginUrl, loginData, headers=loginHeaders).json()
# login check
#print(res)
token_type = res["token_type"]
token = res["access_token"]
auth = token_type + ' ' + token
#auth value check
#print('auth:' + auth)
headers = {'Accept': 'application/json', 'Content-Type': 'application/json', 'Authorization': auth}
url = "http://" + hostname + ":" + port + "/api/widgets/" + did + "/data?limit=" + limit
return requests.post(url, headers=headers).json()