summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYuval Adam <_@yuv.al>2021-05-13 17:03:34 +0300
committerYuval Adam <_@yuv.al>2021-05-13 17:03:34 +0300
commitcb1f9c8d4878eb11fc015f225abcba1d6556e09f (patch)
tree18c30a8d63ff00f5fe4f4d403637dd8c576a2f99
parent8e5ef1dee93b24a515a467f685a190f115010281 (diff)
Handle requests.exceptions.ReadTimeout
-rw-r--r--alarmpy.py8
1 files changed, 7 insertions, 1 deletions
diff --git a/alarmpy.py b/alarmpy.py
index d888330..8e531ef 100644
--- a/alarmpy.py
+++ b/alarmpy.py
@@ -29,10 +29,16 @@ class Alarm(object):
sleep(self.delay)
def fetch(self):
- res = requests.get(self.URL, headers=self.HEADERS, timeout=1)
now = datetime.now()
ts = now.strftime("%Y-%m-%d %H:%M:%S")
+ try:
+ res = requests.get(self.URL, headers=self.HEADERS, timeout=1)
+ except Exception as e:
+ click.secho(f"{ts} ", nl=False)
+ click.secho(f"Exception: {e}", fg="yellow")
+ return
+
if res.content:
click.secho(f"{ts} ", nl=False)
try: