Browse Source

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) <[email protected]>
pull/7/head
Dmitry Ilyin 5 days ago
parent
commit
4f16ecb72f
  1. 2
      AlarmServer.py

2
AlarmServer.py

@ -40,7 +40,7 @@ while True:
sleep(0.1) # Just for recive whole packet sleep(0.1) # Just for recive whole packet
data = conn.recv(len_data) data = conn.recv(len_data)
conn.close() 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(datetime.now().strftime("[%Y-%m-%d %H:%M:%S]>>>"))
print(head, version, session, sequence_number, msgid, len_data) print(head, version, session, sequence_number, msgid, len_data)
print(json.dumps(reply, indent=4, sort_keys=True)) print(json.dumps(reply, indent=4, sort_keys=True))

Loading…
Cancel
Save