PyCharm debug报错:UnicodeDecodeError: 'utf-8' codec can't decode bytes in position 1022-1023: unexpected end of data

作者:刘兴禄
日期:2023年12月30

在用PyCharm 2023 debug报下面的错误:

Traceback (most recent call last):
  File "C:\Develop\PyCharm202303\PyCharm 2023.3\plugins\python\helpers\pydev\_pydevd_bundle\pydevd_comm.py", line 304, in _on_run
    r = r.decode('utf-8')
        ^^^^^^^^^^^^^^^^^
UnicodeDecodeError: 'utf-8' codec can't decode bytes in position 1022-1023: unexpected end of data

用下面的方法成功解决了:

在这里插入图片描述

点击上述位置,跳到下面的源码部分,如下:

在这里插入图片描述

将这里修改为:

r = r.decode('utf-8''ignore')

重启PyCharm就可以了。

报错的的原因是decode()方法的第二个参数errors 的默认值为严格(strict),可以将其修改为ignore

Logo

GitCode 天启AI是一款由 GitCode 团队打造的智能助手,基于先进的LLM(大语言模型)与多智能体 Agent 技术构建,致力于为用户提供高效、智能、多模态的创作与开发支持。它不仅支持自然语言对话,还具备处理文件、生成 PPT、撰写分析报告、开发 Web 应用等多项能力,真正做到“一句话,让 Al帮你完成复杂任务”。

更多推荐