aboutsummaryrefslogtreecommitdiff
path: root/main.py
diff options
context:
space:
mode:
authorArslaan Pathan <[email protected]>2026-10-05 23:51:14 +1300
committerArslaan Pathan <[email protected]>2026-10-05 23:51:14 +1300
commit9640a806a36095c7539b66feb0869f99ef559017 (patch)
tree398608d31d179ac3252b2615dd57979604376189 /main.py
parenta216de8b33c880472fd94ab31000960a1bf0fe0c (diff)
downloadremote-automation-9640a806a36095c7539b66feb0869f99ef559017.tar.xz
remote-automation-9640a806a36095c7539b66feb0869f99ef559017.zip
error handling
Diffstat (limited to 'main.py')
-rw-r--r--main.py16
1 files changed, 14 insertions, 2 deletions
diff --git a/main.py b/main.py
index 0fca35e..489a2f6 100644
--- a/main.py
+++ b/main.py
@@ -1,5 +1,6 @@
from evdev import InputDevice, list_devices, ecodes
from urllib.request import urlopen
+from urllib.error import HTTPError, URLError
SCANCODES = {0x11A: "up", 0x148: "down", 0x147: "left", 0x107: "right", 0x106: "ok", 0x141: "play/pause", 0x11c: "power", 0x103: "vol+", 0x142: "vol-"}
@@ -7,8 +8,19 @@ device = None
last = 0x00
def homelab_request(request: str):
- with urlopen(f"http://192.168.1.96/automate/{request}") as resp:
- print(f"homelab request {request} response {resp.status}")
+ url = f"http://192.168.1.96/automate/{request}"
+
+ try:
+ with urlopen(url, timeout=5) as resp:
+ print(f"homelab request {request} response {resp.status}")
+ print(resp.read().decode())
+
+ except HTTPError as e:
+ print(f"homelab request {request} response {e.code}")
+ print(e.read().decode())
+
+ except URLError as e:
+ print(f"homelab request failed: {e.reason}")
def do_action(action: str):
if action == "ok":