From d753f5938f6e2347668566a1a6ea61fa55baf3a7 Mon Sep 17 00:00:00 2001 From: Nama Date: Sat, 10 Apr 2021 12:18:23 +0200 Subject: [PATCH] Handle ReadTimeout exception on requests --- artemisremotecontrol/__init__.py | 6 +++--- scripts/tasmota.py | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/artemisremotecontrol/__init__.py b/artemisremotecontrol/__init__.py index 98febc5..591ca13 100644 --- a/artemisremotecontrol/__init__.py +++ b/artemisremotecontrol/__init__.py @@ -1,5 +1,5 @@ from requests import get, post -from requests.exceptions import ConnectionError, ChunkedEncodingError +from requests.exceptions import ConnectionError, ChunkedEncodingError, ReadTimeout import logging from os import environ from json import loads, dumps @@ -13,7 +13,7 @@ def _getapiurl(ep): try: response = get(url_endpoints) - except (ConnectionError, ChunkedEncodingError): + except (ConnectionError, ChunkedEncodingError, ReadTimeout): logging.error('Can\'t connect to Artemis') return None if response.status_code != 200: @@ -51,7 +51,7 @@ def setleds(deviceids: list, ledids: list, color: str): logging.debug(data) try: response = post(url, data=str(data)) - except (ConnectionError, ChunkedEncodingError): + except (ConnectionError, ChunkedEncodingError, ReadTimeout): logging.error('Can\'t connect to Artemis to set color') return if response.status_code != 200: diff --git a/scripts/tasmota.py b/scripts/tasmota.py index 8d05435..e67ebd8 100644 --- a/scripts/tasmota.py +++ b/scripts/tasmota.py @@ -5,7 +5,7 @@ from time import sleep from threading import Thread from requests import get -from requests.exceptions import ConnectionError, ChunkedEncodingError +from requests.exceptions import ConnectionError, ChunkedEncodingError, ReadTimeout from artemisremotecontrol.config import Config from artemisremotecontrol import getleds, setleds @@ -26,7 +26,7 @@ def loop(): try: response = get(url, timeout=1) status = response.status_code - except (ConnectionError, ChunkedEncodingError): + except (ConnectionError, ChunkedEncodingError, ReadTimeout): status = False if status != 200: # send "Disconnected" state