From 97e63124d40c42ef1ee2ca54b86a7cf589166bb6 Mon Sep 17 00:00:00 2001
From: Mike Cifelli 1836280-mike-cifelli@users.noreply.gitlab.com
Date: Wed, 8 Feb 2023 08:30:26 -0500
Subject: [PATCH 1/1] Simplify adafruit io error logging
net/adafruit_io.py | 25 +++++++++++--------------
1 file changed, 11 insertions(+), 14 deletions(-)
diff --git a/net/adafruit_io.py b/net/adafruit_io.py
index 46460e7..3c08845 100644
--- a/net/adafruit_io.py
+++ b/net/adafruit_io.py
@@ -19,11 +19,7 @@ class AdafruitIO:
self.url = f'https://io.adafruit.com/api/v2/{username}/groups/{group}/data'
def upload(self, reading):
result = urequests.post(
self.url,
json=self.createPayload(reading),
headers=self.headers
)
result = self.uploadReading(reading)
try:
if result.status_code != 200:
@@ -34,6 +30,13 @@ class AdafruitIO:
finally:
result.close()
return urequests.post(
self.url,
json=self.createPayload(reading),
headers=self.headers
)
def createPayload(self, reading):
payload = {
'created_at': reading['timestamp'],
@@ -49,17 +52,11 @@ class AdafruitIO:
return payload
def logError(self, result):
reason = 'unknown'
status = result.status_code
reason = result.reason.decode("utf-8")
error_message = self.getErrorMessage(result)
if result.status_code == 429:
reason = 'rate limited'
elif result.status_code == 422 and error_message.find('data created_at may not be in the future') == 0:
reason = 'future reading'
else:
reason = f'{result.status_code} - {result.reason.decode("utf-8")}'
logging.debug(f'upload issue: {reason} - "{error_message}"')
logging.debug(f'Adafruit IO upload issue: {status} {reason} - "{error_message}"')
def getErrorMessage(self, result):
try:
--
2.39.5
text/plain
This content has been proxied by September (3851b).