Hi all,
Firstly, let me be clear that I know little about coding, i'm at the beginning of a what seems to be a very steep learning curve so go easy! My background involves hammers and not keyboards!
I have a Raspberry Pi (3) with the hope of learning how to do some basic coding and the first project I have undertaken is to log all of my temperatures in Evohome. I found the following script from a kind poster on this very forum, entered it into a Python 3 environment and keep coming up with the following error. I understand what it is trying to say but I do not understand how to fix it. Can anyone offer any advice.
Traceback (most recent call last):
File "/home/pi/USBHDD/evohome.py", line 18, in <module>
userinfo = json.loads(response.content)
File "/usr/lib/python3.5/json/__init__.py", line 312, in loads
s.__class__.__name__))
TypeError: the JSON object must be str, not 'bytes'
Code below:
Can anyone help? I've tried adding .decode('utf-8') to the end of userinfo = json.loads(response.content) but no luck either.
Firstly, let me be clear that I know little about coding, i'm at the beginning of a what seems to be a very steep learning curve so go easy! My background involves hammers and not keyboards!
I have a Raspberry Pi (3) with the hope of learning how to do some basic coding and the first project I have undertaken is to log all of my temperatures in Evohome. I found the following script from a kind poster on this very forum, entered it into a Python 3 environment and keep coming up with the following error. I understand what it is trying to say but I do not understand how to fix it. Can anyone offer any advice.
Traceback (most recent call last):
File "/home/pi/USBHDD/evohome.py", line 18, in <module>
userinfo = json.loads(response.content)
File "/usr/lib/python3.5/json/__init__.py", line 312, in loads
s.__class__.__name__))
TypeError: the JSON object must be str, not 'bytes'
Code below:
Code:
# Script to monitor and read temperatures from Honeywell EvoHome Web API # Load required libraries import requests import json import datetime import time # Ser your login details in the 2 fields below USERNAME = '########@gmail.com' PASSWORD = '########' # Initial JSON POST to the website to return your userdata url = 'https://rs.alarmnet.com/TotalConnectComfort/WebAPI/api/Session' postdata = {'Username':USERNAME, 'Password':PASSWORD, 'ApplicationId':'91db1612-73fd-4500-91b2-e63b069b185c'} headers = {'content-type':'application/json'} response = requests.post(url,data=json.dumps(postdata),headers=headers) userinfo = json.loads(response.content) # Extract the sessionId and your userid from the response userid = userinfo['userInfo']['userID'] sessionId = userinfo['sessionId'] # Next, using your userid, get all the data back about your site # Print out the headers for our temperatures, this let's us input to .csv file easier for charts url = 'https://rs.alarmnet.com/TotalConnectComfort/WebAPI/api/locations?userId=%s&allData=True' % userid headers['sessionId'] = sessionId response = requests.get(url,data=json.dumps(postdata),headers=headers) fullData = json.loads(response.content)[0] (print) ('Evotemps', 'Evohometemps.csv') for device in fullData['devices']: print (device['name'],',',) print time.sleep (5) # Infinite loop every 5 minutes output temperatures while True: # Next, using your userid, get all the data back about your site url = 'https://rs.alarmnet.com/TotalConnectComfort/WebAPI/api/locations?userId=%s&allData=True' % userid headers['sessionId'] = sessionId response = requests.get(url,data=json.dumps(postdata),headers =headers) fullData = json.loads(response.content)[0] # Get current time and then print all thermostat readings out from datetime import datetime print ,datetime.datetime.now().strftime('%H:%M:%S'),',', for device in fullData['devices']: print (device['thermostat']['indoorTemperature'],',',) print time.sleep(300)
Comment