UnicodeDecodeError: 'gbk' codec can't decode byte 0xab in position 405: illegal multibyte sequence
时间: 2023-10-22 22:28:37 浏览: 88
这错误是因为Python默认使用的编码方式(GBK)无法正确解码包含非ASCII字符的文件。解决这个问题的方法是将文件的编码方式设置为UTF-8。在你的代码中,你可以使用open函数的encoding参数来指定编码方式为UTF-8。例如,在打开文件时,将`open('data/Annotations/%s.xml' % (image_id), 'r', encoding="UTF-8")`改为`open('data/Annotations/%s.xml' % (image_id), 'r', encoding="UTF-8")`。这样就可以正确解码包含非ASCII字符的文件了。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* [pyquery报错:UnicodeDecodeError: ‘gbk’ codec can’t decode byte](https://download.csdn.net/download/weixin_38665944/13751270)[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^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 33.333333333333336%"]
- *2* [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^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 33.333333333333336%"]
- *3* [UnicodeDecodeError: ‘gbk‘ codec can‘t decode byte 0xab in position 105: illegal multibyte seque](https://blog.csdn.net/magicnnonn/article/details/124342022)[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^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 33.333333333333336%"]
[ .reference_list ]
阅读全文