From 4f16ecb72f52da6923138923e27489d18043ce0b Mon Sep 17 00:00:00 2001 From: Dmitry Ilyin <6576495+widgetii@users.noreply.github.com> Date: Sat, 30 May 2026 18:40:40 +0300 Subject: [PATCH] AlarmServer: fix crash on Python 3.9+ (json.loads encoding kwarg) The `encoding` keyword argument to `json.loads` was deprecated in Python 3.1 and removed in 3.9, so `AlarmServer.py` has been crashing on the very first received packet under any modern Python install: TypeError: JSONDecoder.__init__() got an unexpected keyword argument 'encoding' Decode the bytes once and strip the framing tail (`\x00\n`) before handing the string to `json.loads`. Verified with a self-test packet on Python 3.13. Co-Authored-By: Claude Opus 4.7 (1M context) --- AlarmServer.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/AlarmServer.py b/AlarmServer.py index f8106e3..7acf45e 100644 --- a/AlarmServer.py +++ b/AlarmServer.py @@ -40,7 +40,7 @@ while True: sleep(0.1) # Just for recive whole packet data = conn.recv(len_data) conn.close() - reply = json.loads(data, encoding="utf8") + reply = json.loads(data.decode("utf-8", errors="replace").rstrip("\x00\n")) print(datetime.now().strftime("[%Y-%m-%d %H:%M:%S]>>>")) print(head, version, session, sequence_number, msgid, len_data) print(json.dumps(reply, indent=4, sort_keys=True))