Created
July 28, 2017 18:36
-
-
Save automactic/778287df645bf8c9aaa1e0aa6e2ee268 to your computer and use it in GitHub Desktop.
python KSensor WebAPI request sample code
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from datetime import datetime | |
import json | |
import urllib.request | |
def send_data(url: str, sid, pknnmb, timestamp: datetime, baseline, stddev, measures): | |
payload = { | |
'sid': str(sid), | |
'pknmb': str(pknnmb), | |
'timestamp': timestamp.strftime('%Y-%m-%d %H:%M:%S'), | |
'baseline': baseline, | |
'stddev': stddev, | |
'measures': measures, | |
} | |
headers = {'Content-Type': 'application/json; charset=utf-8'} | |
request = urllib.request.Request(url, json.dumps(payload).encode('utf-8'), headers) | |
with urllib.request.urlopen(request) as response: | |
json_response = json.loads(response.read().decode('utf-8')) | |
# print(json_response) | |
return json_response['success'] == 'true' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment