Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- import requests
- import getpass
- import json
- class TempObj(object):
- def __init__(self,data):
- self.__dict__ = json.load(data)
- def checkStatusCode(status_code, Url):
- if status_code == 200 or status_code == 201:
- return
- else:
- print("Call to URL {0} failed with status code {1}".format(Url,status_code))
- print("Exiting")
- exit(1)
- def getDeviceHeader():
- global deviceHeader
- authHeaders = {"Content-Type": "application/x-www-form-urlencoded; charset=UTF-8"}
- userName = input("Concert username[iotpadminuser] ") or "iotpadminuser"
- password = "P@55w0rd"
- authUrl = 'https://sso.pool4.iotpdev.com/auth/realms/authenticate/protocol/openid-connect/token'
- try:
- print("authURL: {0}".format(authUrl))
- response = requests.post(authUrl,
- headers = authHeaders,
- data = {"client_id" : "postman",
- "username" : userName,
- "password" : password,
- "grant_type" : "password"
- }
- )
- checkStatusCode(response.status_code,authUrl)
- print (response)
- except requests.exceptions.ConnectionError as connErr:
- print("Connection Error: {0}".format(str(connErr)))
- exit(1)
- except requests.exceptions.RequestException as e:
- print("Response Exception Raised on auth URL: {0}".format(str(e)))
- print("Address exception: Quitting")
- exit(1)
- deviceHeader = {"Authorization" : "Bearer " + response.json()['access_token'],
- "Content-Type" : "application/json"}
- def tempRequest():
- req = requests.get('https://api.pool4.iotpdev.com/api/1/devices/fb903ae2-67de-46cb-8cb7-9eb3faf62e1d/sensors/e370df3d-6283-459f-9d8e-0b614dec578b', headers = deviceHeader)
- print(req.json())
- #tempObj = TempObj(req.json())
- #print(tempObj.a)
- def humRequest():
- req = requests.get('https://api.pool4.iotpdev.com/api/1/devices/fb903ae2-67de-46cb-8cb7-9eb3faf62e1d/sensors/7021ee31-f8b2-4b38-bd4f-14fbec90fd87', headers = deviceHeader)
- print(req.json())
- def lightRequest():
- req = requests.get('https://api.pool4.iotpdev.com/api/1/devices/fb903ae2-67de-46cb-8cb7-9eb3faf62e1d/sensors/6c8810fe-8c78-4fec-bd54-e9586975da98', headers = deviceHeader)
- print(req.json())
- def postRequest():
- print("post request started")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement