Skip to content

Commit

Permalink
Handle ReadTimeout exception on requests
Browse files Browse the repository at this point in the history
  • Loading branch information
Nama committed Apr 10, 2021
1 parent 88bf77d commit d753f59
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
6 changes: 3 additions & 3 deletions artemisremotecontrol/__init__.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions scripts/tasmota.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down

0 comments on commit d753f59

Please sign in to comment.