UnicodeDecodeError: 'gbk' codec can't decode byte 0xac in position 929985: illegal multibyte sequence
时间: 2023-08-14 13:03:39 浏览: 140
这个错误是因为在读取文件时使用了错误的编码方式导致的。当文件中包含中文字符时,需要使用正确的编码方式才能正确读取文件内容。这个错误通常在处理NLP中遇到。有几种常见的解决方法可以尝试:
1. 将文件的编码方式改为utf-8:将`with open(file) as f:`改为`with open(file, 'r', encoding='utf-8') as f:`,这样就使用了utf-8编码方式来读取文件内容。这样可以确保正确读取包含中文字符的文件内容。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* *2* [Python报错UnicodeDecodeError: ‘gbk‘ codec can‘t decode byte](https://blog.csdn.net/sweet_tea_/article/details/125372604)[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 style="max-width: 50%"]
- *3* [UnicodeDecodeError: ‘gbk‘ codec can‘t decode byte 0xac in position 14: illegal multibyte sequence...](https://blog.csdn.net/yang___y/article/details/131253063)[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 style="max-width: 50%"]
[ .reference_list ]
阅读全文