You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Sometimes when getting the time, the following error occurs:
Hardware is PyPortal Adafruit Product ID: 4116
------ START: Error Message ------
File "adafruit_portalbase/network.py", line 208, in get_strftime
AttributeError: 'NoneType' object has no attribute 'get'
------ END: Error Message ------
Line 208: response = self._wifi.requests.get(api_url, timeout=10)
Not certain why this happens but it is not every time. Perhaps one in 5 connection attempts.
My workaround has been to catch all exceptions when attempting to get the time.
def getTime(lastRefreshedTime, secondsToUpdate):
if pyportal is None:
return None
if (not lastRefreshedTime) or (time.monotonic() - lastRefreshedTime) > secondsToUpdate:
eventWindow.statusDateTime.text = "Updating Time"
try:
print("INFO: Getting time from internet!")
if (not lastRefreshedTime):
eventWindow.changeBackground(
eventWindow.IMG_FILE_CONNECTING_BACKGROUND, False)
start = time.time()
pyportal.get_local_time() # pyportal.get_local_time(false) non-blocking?
print(f"INFO: Getting time took {time.time() - start} seconds.")
lastRefreshedTime = time.monotonic()
print("INFO: Success the time has been set.")
except RuntimeError as e:
print(f"WARN: Some error occured, retrying!\r\n{e}")
if (not lastRefreshedTime):
eventWindow.changeBackground(
eventWindow.IMG_FILE_CONNECT_FAILED_BACKGROUND, False)
# Use try catch here as there is an error in adafruit_portalbase
# File "adafruit_portalbase/network.py", line 208, in get_strftime
# AttributeError: 'NoneType' object has no attribute 'get'
except Exception as e:
print(f"ERROR: Failed to getTime\r\n{e}")
eventWindow.changeBackground(
eventWindow.IMG_FILE_CONNECT_FAILED_BACKGROUND, False)
removePastEvents()
return lastRefreshedTime
Sometimes when getting the time, the following error occurs:
Hardware is PyPortal Adafruit Product ID: 4116
------ START: Error Message ------
File "adafruit_portalbase/network.py", line 208, in get_strftime
AttributeError: 'NoneType' object has no attribute 'get'
------ END: Error Message ------
Line 208: response = self._wifi.requests.get(api_url, timeout=10)
Not certain why this happens but it is not every time. Perhaps one in 5 connection attempts.
My workaround has been to catch all exceptions when attempting to get the time.
Full code with the workaround is available at https://github.com/richteel/PyPortal_Events. Direct link to the code.py file is https://github.com/richteel/PyPortal_Events/blob/main/PyPortal/code.py.
The text was updated successfully, but these errors were encountered: