UnicodeDecodeError: 'gbk' codec can't decode byte 0x8c in position 646: illegal multibyte sequence
时间: 2023-09-25 15:14:50 浏览: 83
这个错误是由于在使用open方法读取文件时,文件的编码格式与默认的编码格式不匹配导致的。在Windows电脑上,默认的编码格式是gbk,如果你打开的文件是以utf-8编码格式保存的,就会出现这个错误。解决这个问题的方法很简单,只需要在open方法中指定文件的编码格式为utf-8即可。修改前的代码是open(file_path, 'r'),你可以将其修改为open(file_path, 'r', encoding='utf-8')。这样就可以正确读取以utf-8编码格式保存的文件了。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* [UnicodeDecodeError: ‘gbk‘ codec can‘t decode byte 0x8c in position 62: illegal multibyte sequence](https://blog.csdn.net/lcecube/article/details/131174244)[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%"]
- *2* *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^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 50%"]
[ .reference_list ]
阅读全文