pymavlink
pymavlink copied to clipboard
Mavlogdump fails on tlog with .log suffix
Mavlogdump fails on tlogs that have a .log suffix.
Traceback (most recent call last):
File "/home/borgers/projects/MAVProxy/env/bin/mavlogdump.py", line 4, in <module>
__import__('pkg_resources').run_script('pymavlink==2.4.31', 'mavlogdump.py')
File "/home/borgers/projects/MAVProxy/env/lib/python3.10/site-packages/pkg_resources/__init__.py", line 651, in run_script
self.require(requires)[0].run_script(script_name, ns)
File "/home/borgers/projects/MAVProxy/env/lib/python3.10/site-packages/pkg_resources/__init__.py", line 1448, in run_script
exec(code, namespace, namespace)
File "/home/borgers/projects/MAVProxy/env/lib/python3.10/site-packages/pymavlink-2.4.31-py3.10-linux-x86_64.egg/EGG-INFO/scripts/mavlogdump.py", line 83, in <module>
mlog = mavutil.mavlink_connection(filename, planner_format=args.planner,
File "/home/borgers/projects/MAVProxy/env/lib/python3.10/site-packages/pymavlink-2.4.31-py3.10-linux-x86_64.egg/pymavlink/mavutil.py", line 1776, in mavlink_connection
if DFReader.DFReader_is_text_log(device):
File "/home/borgers/projects/MAVProxy/env/lib/python3.10/site-packages/pymavlink-2.4.31-py3.10-linux-x86_64.egg/pymavlink/DFReader.py", line 1045, in DFReader_is_text_log
ret = (f.read(8000).find('FMT,') != -1)
File "/usr/lib/python3.10/codecs.py", line 322, in decode
(result, consumed) = self._buffer_decode(data, self.errors, final)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xe4 in position 2: invalid continuation byte
The DFReader_is_text_log function opens the binary file as text file and tries to do UTF-8 decoding which does not work in case of a binary tlog file. This happens because we assume that files with suffix .log can be opened as text: https://github.com/ArduPilot/pymavlink/blob/master/mavutil.py#L1773
We should not make such assumptions.
One solution could be to wrap the opening of the file in DFReader_is_text_log into a try/catch and return False in case of a exception.