读取文本文件返回UnicodeDecodeError:'utf-8'编解码器无法在Python中解码字节0x92 [英] Read text file returns UnicodeDecodeError: 'utf-8' codec can't decode byte 0x92 in Python
本文介绍了读取文本文件返回UnicodeDecodeError:'utf-8'编解码器无法在Python中解码字节0x92的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
即使我提到编码
,我仍在使用Python3读取文本文件,但它会重新运行:
I'm reading a text file using Python3 even I have mentioned encoding
but it retruns:
UnicodeDecodeError:'utf-8'编解码器无法解码位置96的字节0x92:无效的起始字节
[05 / May / 2018 03:35:45] POST / app / HTTP / 1.1 500 14383
UnicodeDecodeError: 'utf-8' codec can't decode byte 0x92 in position 96: invalid start byte [05/May/2018 03:35:45] "POST /app/ HTTP/1.1" 500 14383
这不是重复项,但特定于 byte 0x92
It's not a duplicate but it's specific to byte 0x92
.
这是我尝试过的内容:
txt = Path(text_path).read_text(encoding="utf-8")
推荐答案
您的文本文件可能未使用utf-8编码。您可能想尝试其他编码,例如 encoding ='cp1252'
Your textfile probably isn't encoded in utf-8. You might want to try a different encoding, e.g. encoding='cp1252'
这篇关于读取文本文件返回UnicodeDecodeError:'utf-8'编解码器无法在Python中解码字节0x92的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文