From 68d65fa33ba95e190c7a37601fd20b10c56df32a Mon Sep 17 00:00:00 2001 From: zecoj Date: Mon, 19 Aug 2019 15:52:18 +1000 Subject: [PATCH 1/3] adding .decode('utf-8') Fix the following error in some instances: TypeError: the JSON object must be str, not 'bytes' --- app.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app.py b/app.py index 6affe6d..67e8914 100644 --- a/app.py +++ b/app.py @@ -138,7 +138,7 @@ def login(): response = requests.post(functions.BASE_URL + "account/login", data=payload, headers=headers) returnHeaders = response.headers - returnContent = json.loads(response.text) + returnContent = json.loads(response.text.decode('utf-8')) try: # If there was an error logging in, redirect to the index page with the 7Eleven response @@ -354,7 +354,7 @@ def lockin(): returnContent = response.content # Move the response json into an array so we can read it - returnContent = json.loads(returnContent) + returnContent = json.loads(returnContent.decode('utf-8')) # If there is a fuel lock already in place we get an error! try: @@ -406,7 +406,7 @@ def lockin(): response = requests.post(functions.BASE_URL + "FuelLock/Confirm", data=payload, headers=headers) # Get the response into a json array - returnContent = json.loads(response.content) + returnContent = json.loads(response.content.decode('utf-8')) try: # Check if the response was an error message if(returnContent['Message']): From 77c2f0d773947baa3cbfe7900acb394b1f2be44f Mon Sep 17 00:00:00 2001 From: zecoj Date: Mon, 19 Aug 2019 15:55:21 +1000 Subject: [PATCH 2/3] adding .decode('utf-8') Fix the following error in some instances: TypeError: the JSON object must be str, not 'bytes' --- autolocker.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/autolocker.py b/autolocker.py index 1586ae3..93d09a6 100644 --- a/autolocker.py +++ b/autolocker.py @@ -113,7 +113,7 @@ def check_fuellock(accessToken, deviceSecret, DEVICE_ID): # Send the request and get the response into a JSON array response = requests.get(functions.BASE_URL + "FuelLock/List", headers=headers) - returnContent = json.loads(response.content) + returnContent = json.loads(response.content.decode('utf-8')) config = configparser.ConfigParser() @@ -231,7 +231,7 @@ def start_lockin(): # Send through the request and get the response response = requests.post(functions.BASE_URL + "FuelLock/Confirm", data=payload, headers=headers) - returnContent = json.loads(response.content) + returnContent = json.loads(response.content.decode('utf-8')) try: if(returnContent['Message']): From 468b08a206282f39eaf14b853586bbe220892480 Mon Sep 17 00:00:00 2001 From: zecoj Date: Mon, 19 Aug 2019 15:56:28 +1000 Subject: [PATCH 3/3] adding .decode('utf-8') Fix the following error in some instances: TypeError: the JSON object must be str, not 'bytes' --- functions.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/functions.py b/functions.py index 114c7aa..4112ebd 100644 --- a/functions.py +++ b/functions.py @@ -172,7 +172,7 @@ def lockedPrices(): 'X-DeviceSecret':session['deviceSecret']} response = requests.get(BASE_URL + "FuelLock/List", headers=headers) - returnContent = json.loads(response.content) + returnContent = json.loads(response.content.decode('utf-8')) # An error occours if we have never locked in a price before try: