'gbk' codec can't decode byte 0x99 in position 1148729: illegal multibyte sequence
时间: 2023-08-10 09:08:43 浏览: 188
这个错误是由于Python的open方法默认编码取决于平台,如果是Windows平台,默认编码是gbk,而如果文件是utf-8编码,就会报这个错误。解决办法是在打开文件的代码中指定编码方式为utf-8,例如:txtfile = open('testdata1.txt', 'r', encoding='utf-8')。这样就可以正确读取文件内容了。\[1\]
至于你提到的'gbk' codec can't decode byte 0x99 in position 1148729: illegal multibyte sequence错误,这个错误是由于在读取文件时遇到了非法的多字节序列。可能是文件中包含了无法被gbk编码解析的字符。解决办法是使用正确的编码方式打开文件,例如utf-8。你可以尝试使用相同的方法来解决这个问题。\[2\]
#### 引用[.reference_title]
- *1* [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^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item]
- *2* *3* [UnicodeDecodeError: ‘gbk‘ codec can‘t decode byte 0x80 in position 198: illegal multibyte sequence](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^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item]
[ .reference_list ]
阅读全文