Repository navigation
Closed
Description
Problem Description
The natnet python library (v0.2.0) crashes when connecting to newer Motive servers (e.g., Motive 3.3.0 which uses NatNet Protocol 4.2).
The crashes occur in two places:
- UnicodeDecodeError: When parsing strings in
MODELDEFpackets usingPacketBuffer.read_string. The newer protocol seems to send bytes that are not strictly valid utf-8 in the expected context or the parsing offset is misaligned. - struct.error: When parsing
DataDescriptions. Because the library does not support Protocol 4.X, it fails to account for new fields or size changes in the packet structure, leading to invalid pointer offsets.
my-computer@abode:~/home/tests$ python3 test_natnet.py
Traceback (most recent call last):
File "/home/hello-robot/repos/stretch_production_tools_ii/test_natnet_repro.py", line 26, in <module>
streaming_client.update_sync()
File "/home/hello-robot/.local/lib/python3.12/site-packages/natnet/nat_net_client.py", line 268, in update_sync
while self.__process_socket(
^^^^^^^^^^^^^^^^^^^^^^
File "/home/hello-robot/.local/lib/python3.12/site-packages/natnet/nat_net_client.py", line 144, in __process_socket
self.__process_message(PacketBuffer(data))
File "/home/hello-robot/.local/lib/python3.12/site-packages/natnet/nat_net_client.py", line 176, in __process_message
data_descs = DataDescriptions.read_from_buffer(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/hello-robot/.local/lib/python3.12/site-packages/natnet/data_descriptions.py", line 346, in read_from_buffer
unpacked_data = desc_type.read_from_buffer(buffer, protocol_version)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/hello-robot/.local/lib/python3.12/site-packages/natnet/data_descriptions.py", line 24, in read_from_buffer
marker_names = [buffer.read_string() for _ in range(marker_count)]
^^^^^^^^^^^^^^^^^^^^
File "/home/hello-robot/.local/lib/python3.12/site-packages/natnet/packet_buffer.py", line 24, in read_string
str_dec = str_enc.decode("utf-8")
^^^^^^^^^^^^^^^^^^^^^^^
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xa7 in position 0: invalid start byte
Metadata
Metadata
Assignees
Labels
No labels
Activity
hello-bharadwaj commentedon Feb 5, 2026
I have raised a PR with a small patch as a fix for this issue that worked on my end. I hope it helps. @TimSchneider42
TimSchneider42 commentedon Feb 6, 2026
Can you check if #7 fixes this issue?
hello-bharadwaj commentedon Feb 6, 2026