UnicodeDecodeError: 'gbk' codec can't decode byte 0x9c in position 151: illegal multibyte sequence
时间: 2023-08-10 09:08:43 浏览: 138
basemap readshapefile UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb4 in position 0-附件资源
这个错误是由于Python的open方法默认编码取决于平台,如果是Windows平台,默认编码是gbk,而如果文件是utf-8编码,就会报这个错误。解决办法是在打开文件的代码中指定编码为utf-8。例如,将代码修改为txtfile = open('testdata1.txt', 'r', encoding='utf-8')。这样就可以正确读取文件内容了。\[2\]
#### 引用[.reference_title]
- *1* [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^v91^control,239^v3^insert_chatgpt"}} ] [.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^v91^control,239^v3^insert_chatgpt"}} ] [.reference_item]
- *3* [UnicodeDecodeError: ‘gbk‘ codec can‘t decode byte 0x80 in position 198: illegal multibyte ...](https://blog.csdn.net/hhhhhhhhhhwwwwwwwwww/article/details/128225609)[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^v91^control,239^v3^insert_chatgpt"}} ] [.reference_item]
[ .reference_list ]
阅读全文