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

【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命令,全部解析出来了


http://www.kler.cn/a/559765.html

相关文章:

  • 一文讲解Redis中的混合持久化
  • 学术论文项目网站搭建教程【Github】
  • mysql的源码包安装
  • 【杂谈】-强化学习遇见链式思维:将大型语言模型转变为自主推理代理
  • Python 函数(传递任意数量的实参)
  • jmeter 与大数据生态圈中的服务进行集成
  • 软件工程和系统分析与设计
  • 算法随笔_58: 队列中可以看到的人数
  • leetcode - hot100 - python - 专题二:双指针
  • 【STM32 基于PID的闭环电机控制系统】
  • C语言学习,插入排序
  • Linux内核,slub分配流程
  • go 接口interface func (m Market) getName() string {
  • KubeKey一键安装部署k8s集群和KubeSphere详细教程
  • 2025-2-21 leetcode刷题情况(二叉树的修改与构造)
  • JAVAweb-JS基本数据类型,变量,DOM,pop,push函数,事件
  • 基于计算机视觉的手势识别:让机器理解我们的手势语言
  • DeepSeek安装部署笔记(一)
  • VMware中安装的ubuntu虚拟机屏幕由居中设置为最大化
  • 人工智能(AI):科技新纪元的领航者