栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

UnicodeDecodeError: ‘utf-8‘ codec can‘t decode byte 0xff in position

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

UnicodeDecodeError: ‘utf-8‘ codec can‘t decode byte 0xff in position

在使用python解释MTK的log时候,提示“codec can't decode byte 0xff in position 5145: illegal multibyte sequence”

主要是因为MTK输出的log中,有部分字符采用1-2个字节,导致使用utf-8或者gbk编码方式都无法解释。只需要将编码方式改成encoding="ISO-8859-1"即可

Traceback (most recent call last):
  File "extract-power-consumption-comparison-data--mtk.py", line 341, in
    parse_process(input_file,fileToColumn)
  File "extract-power-consumption-comparison-data--mtk.py", line 46, in parse_process
    for line in input_file:
UnicodeDecodeError: 'gbk' codec can't decode byte 0xff in position 5145: illegal multibyte sequence

或者

Traceback (most recent call last):
  File "extract-power-consumption-comparison-data--mtk.py", line 341, in
    parse_process(input_file,fileToColumn)
  File "extract-power-consumption-comparison-data--mtk.py", line 46, in parse_process
    for line in input_file:
  File "/usr/lib/python3.5/codecs.py", line 321, in decode
    (result, consumed) = self._buffer_decode(data, self.errors, final)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position 5145: invalid start byte

解决方法:

input_file = open(inputfile[nameIndex], 'r',encoding="ISO-8859-1")

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/360651.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号