当前位置: 首页 > news >正文

【PX4日志解析报错】pyulog工具解析日志出错

px4的日志文件一直通过pyulog做解析 但是发现有的时候会出现错误,解析不了,使用网站解析也会失败,但是这把数据很重要所以想办法必须解决,报错如下

zzh@zzh-System-Product-Name:~/Desktop/log/log223/log42$ ulog_info -m MESSAGE log_42_2025-2-23-17-08-34.ulg 
Traceback (most recent call last):
  File "/home/zzh/.local/bin/ulog_info", line 8, in <module>
    sys.exit(main())
  File "/home/zzh/.local/lib/python3.8/site-packages/pyulog/info.py", line 85, in main
    ulog = ULog(ulog_file_name, None, disable_str_exceptions)
  File "/home/zzh/.local/lib/python3.8/site-packages/pyulog/core.py", line 138, in __init__
    self._load_file(log_file, message_name_filter_list)
  File "/home/zzh/.local/lib/python3.8/site-packages/pyulog/core.py", line 823, in _load_file
    self._read_file_definitions()
  File "/home/zzh/.local/lib/python3.8/site-packages/pyulog/core.py", line 868, in _read_file_definitions
    msg_info = self._MessageInfo(data, header, is_info_multiple=True)
  File "/home/zzh/.local/lib/python3.8/site-packages/pyulog/core.py", line 562, in __init__
    self.value = ULog.parse_string(data[1+key_len:])
  File "/home/zzh/.local/lib/python3.8/site-packages/pyulog/core.py", line 93, in parse_string
    ret = _parse_string(cstr)
  File "/home/zzh/.local/lib/python3.8/site-packages/pyulog/core.py", line 19, in _parse_string
    return str(cstr, 'utf-8', errors)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xe5 in position 218: unexpected end of data

定位问题,我是用linux,找到运行的包pyulog包,在python3.8下面
打开这个core.py文件
找到报错的这个函数_parse_string

@staticmethod
    def parse_string(cstr):
        """
        wrapper for _parse_string with
        parametrized exception handling
        """
        ret = ''
        if _RUNNING_PYTHON3 and ULog._disable_str_exceptions:
            ret = _parse_string(cstr, 'ignore')
        else:
            ret = _parse_string(cstr)
        return ret

经过deepseek指点,把else后面的分支改成

        else:
            # 默认使用 'replace' 替换无法解码的字节
            ret = _parse_string(cstr, 'replace')

保存后,再次运行pyulog命令,全部解析出来了

相关文章:

  • 【管道 】
  • STM32的HAL库开发---ADC采集内部温度传感器
  • 大疆激光雷达录制的bag包无法解析出topic怎么办?
  • 【Blender】二、建模篇--07,置换修改器
  • 第14篇:Vue Router 高级用法与路由守卫
  • 2025教育与科研领域实战全解析:DeepSeek赋能细分场景深度指南(附全流程案例与资源)
  • Android 实现 RTMP 推流:快速集成指南
  • PyTorch 是如何进行机器学习的
  • stm32108键C-B全调性_动态可视化乐谱钢琴
  • conda 基本命令
  • HttpWatch 9.4.17 Pro网页调试与性能优化 资源工具分享
  • Leetcode-42. Trapping Rain Water [C++][Java]
  • 能否在delete一个指针后继续使用它以及原因
  • MQTT实现智能家居------3、源码分析(超详细)
  • JavaScript中的call方法相关知识点
  • ZLG嵌入式笔记 | 为什么你的网卡工作会不正常?(上
  • 鸿蒙学习-
  • ctf网络安全题库 ctf网络安全大赛答案
  • JSP学习
  • MybatisPlus-注解
  • 平台骗了钱/哈尔滨网络优化推广公司
  • 杭州哪家公司做网站好/网络优化工具app手机版
  • 施工企业承揽业务不良行为/优化大师怎么卸载
  • wordpress主题中文主题下载/seo快速排名上首页
  • 玉溪网站建设/网络推广工作室
  • 三亚谁做网站/百度推广账户优化