UnicodeDecodeError: 'gbk' codec can't decode byte 0x86 in position 331: illegal multibyte sequence
时间: 2023-08-13 10:08:14 浏览: 214
这个错误是由于Python默认使用的编码是gbk,而在读取文件时,文件的编码是utf-8,导致无法解码。你可以通过在打开文件的代码中添加`encoding='utf-8'`参数来解决这个问题,例如`txtfile = open('testdata1.txt','r', encoding='utf-8')`。此外,你还可以尝试在其他相关的文件中也添加`encoding='utf-8'`参数来确保文件的编码正确。这样做应该可以解决你遇到的报错。<em>1</em><em>2</em><em>3</em>
#### 引用[.reference_title]
- *1* *3* [UnicodeDecodeError: ‘gbk’ codec can’t decode byte 0x80 in position 2467: illegal multibyte ...](https://blog.csdn.net/wujiaojue/article/details/129906085)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}} ] [.reference_item]
- *2* [UnicodeDecodeError: ‘gbk‘ codec can‘t decode byte 0x9a in position 52: illegal multibyte sequence](https://blog.csdn.net/qq_45352961/article/details/130232120)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}} ] [.reference_item]
[ .reference_list ]
阅读全文