Skip to content

Commit

Permalink
Do not error out on malformed JSON (#7)
Browse files Browse the repository at this point in the history
Once our RFC 3 (FW version B3.5.50) gets connected to the network, its
`net_status` JSON data include the `ip` and `mac` fields whose values
are binary strings, and that results in a Python-level exception:
```
UnicodeDecodeError: 'utf-8' codec can't decode byte 0x9e in position 713: invalid start byte
```
The `mac` is a 12-byte string for me (unless all the escape sequences
failed me, it's really late). I have no idea what that is, whether it's
something related to BLE MACs (two addresses in a row?), or something to
do with cryptography.

The `ip` is a four-byte string which for me is `L^\x9e\xbe`. No matter
what byte order I use, it doesn't map to the IPv4 address that our home
is NATed behind, or (according to whois) to any obvious cloud provider.
Another mysterious field.

No matter what these fields are, let's not break JSON parsing, and let's
keep as much info as possible (which is why I picked that particular
error handler as per PEP 383).

Co-authored-by: Lauris BH <[email protected]>
  • Loading branch information
jktjkt and lafriks authored Jan 28, 2024
1 parent 961db65 commit 498e1c1
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion karcher/karcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ def _process_mqtt_message(self, topic, msg):
return

if 'thing/service/property/get_reply' in topic:
data = json.loads(msg)
data = json.loads(msg.decode('utf-8', 'surrogateescape'))
if data['code'] != 0:
# TODO: handle error
return
Expand Down

0 comments on commit 498e1c1

Please sign in to comment.