Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not error out on malformed JSON #7

Merged
merged 2 commits into from
Jan 28, 2024

Conversation

jktjkt
Copy link
Contributor

@jktjkt jktjkt commented Jan 28, 2024

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).

jktjkt and others added 2 commits January 28, 2024 02:28
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).
@lafriks lafriks merged commit 498e1c1 into lafriks:main Jan 28, 2024
1 check passed
@lafriks
Copy link
Owner

lafriks commented Jan 28, 2024

It's probably encrypted, did you try use method decrypt from utils.py?

@jktjkt
Copy link
Contributor Author

jktjkt commented Feb 11, 2024

It's probably encrypted, did you try use method decrypt from utils.py?

No joy there, it's not a base64 string. And when I base64-encode it first and then feed that stuff to karcher.utils.decrypt, I get an error TypeError: ord() expected a character, but string of length 0 found.

Anyway, I'm behind a carrier-grade NAT, and I'm getting \x4c\x4e\xba\xbe in the ip field today, and it looks like I'm getting mapped to 176.114.240.18 by my ISP's CGNAT. The previous value a few weeks ago was \x4c\x5e\x9e\xbe. The local IPv4 address of the robot is currently 172.30.70.12.

I reconfigured my router so that it assigns a different address, 172.30.70.13, and after power-cycling the device, it's now L\\u001e\x80\xbe (yeah, that's 9 bytes now, not 4: 0x4c, 0x5c, 0x75, 0x30, 0x30, 0x31, 0x65, 0x80, 0xbe). One reboot later, it's L\xde\xe0\xbe, AKA \x4c\xde\xe0\xbe.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants