'gbk' codec can't decode byte 0x85 in position 8: illegal multibyte sequence
时间: 2023-08-10 22:05:52 浏览: 316
引用\[2\]:在做YoloV5剪枝的时候,遇到如下问题; return load(stream, SafeLoader) File "D:\Users\wh109\anaconda3\lib\site-packages\yaml\__init__.py", line 79, in load loader = Loader(stream) File "D:\Users\wh109\anaconda3\lib\site-packages\yaml\loader.py", line 34, in __init__ Reader.__init__(self, stream) File "D:\Users\wh109\anaconda3\lib\site-packages\yaml\reader.py", line 85, in __init__ self.determine_encoding() File "D:\Users\wh109\anaconda3\lib\site-packages\yaml\reader.py", line 124, in determine_encoding self.update_raw() File "D:\Users\wh109\anaconda3\lib\site-packages\yaml\reader.py", line 178, in update_raw data = self.stream.read(size) UnicodeDecodeError: 'gbk' codec can't decode byte 0x80 in position 198: illegal multibyte sequence。
问题:'gbk' codec can't decode byte 0x85 in position 8: illegal multibyte sequence
回答: 这个错误是由于编码问题导致的。'gbk' codec无法解码字节0x85,因为它是一个非法的多字节序列。这可能是因为你的代码或文件中包含了无法被'gbk'编码解析的字符。解决这个问题的方法是将编码格式更改为能够正确解析这些字符的编码格式,例如'utf-8'。你可以尝试在代码中添加以下行来更改编码格式:
```python
import sys
reload(sys)
sys.setdefaultencoding('utf-8')
```
这将把编码格式更改为'utf-8',以便能够正确解析包含非法多字节序列的字符。请注意,这个解决方法可能因你的具体情况而有所不同,你可能需要根据你的代码和文件的实际情况进行适当的调整。
#### 引用[.reference_title]
- *1* [Python读取文件时出现UnicodeDecodeError: 'gbk' codec can't decode byte 0x80 in position xx: 解决方案](https://blog.csdn.net/zhang__shuang_/article/details/82527314)[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^control_2,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^control_2,239^v3^insert_chatgpt"}} ] [.reference_item]
[ .reference_list ]
阅读全文