UnicodeDecodeError: 'gbk' codec can't decode byte 0x80 in position 206: illegal multibyte sequence
时间: 2023-08-13 20:04:50 浏览: 144
关于GBK和Unicode字符集转换乱码问题
3星 · 编辑精心推荐
这个错误是由于编码问题导致的。根据引用和引用,报错信息中的'gbk'编码无法解码对应位置的字节,这是因为在打开文件时没有指定正确的编码格式。解决方法是在打开文件时指定编码格式为utf-8,即将open()方法中的encoding参数改为'UTF-8'。以下是修改后的代码示例:
```
with open(save_dir / 'hyp.yaml', 'w', encoding='UTF-8') as f:
yaml.dump(hyp, f, sort_keys=False)
with open(save_dir / 'opt.yaml', 'w', encoding='UTF-8') as f:
yaml.dump(vars(opt), f, sort_keys=False)
```
通过这样的修改,可以确保正确的编码格式,避免UnicodeDecodeError错误的出现。<em>1</em><em>2</em><em>3</em>
#### 引用[.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^v92^chatsearchT3_1"}} ] [.reference_item]
- *2* [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^chatsearchT3_1"}} ] [.reference_item]
- *3* [UnicodeDecodeError: ‘gbk‘ codec can‘t decode byte 0x80 in position 218: illegal multibyte ...](https://blog.csdn.net/Vertira/article/details/127453942)[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^chatsearchT3_1"}} ] [.reference_item]
[ .reference_list ]
阅读全文