使用 pdb 时出现 Django UnicodeDecodeError
我注意到每次我
import pdb; pdb.set_trace()
在我的西班牙语 Django 项目中放置一个:时,如果我在字符串中包含特定的 Unicode 字符,例如:
Gracias por tu colaboración
我会在 Django 调试窗口中收到带有“序号不在范围(128)”的 UnicodeDecodeError 。问题是我无法轻松调试我的应用程序。另一方面,如果我使用 ipdb,我会得到类似这样的信息:
ERROR - failed to write data to stream: <open file '<stdout>', mode 'w' at 0x7f3d43e34140>
我已经在 google 上搜索找到了解决方案,但看起来我是唯一遇到此问题的人:)
I've notice every time I put an:
import pdb; pdb.set_trace()
in My Spanish Django project, if I have a specific Unicode character in a string like:
Gracias por tu colaboración
I get a UnicodeDecodeError with an 'ordinal not in range(128)' in a Django Debug window. The problem is that I can not debug my application easily. On the other hand If I use ipdb I get things like:
ERROR - failed to write data to stream: <open file '<stdout>', mode 'w' at 0x7f3d43e34140>
I've googled to find a solution, but it looks like I'm the only one having this issue :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我发现另一个程序员已将其添加到视图文件的开头,这会破坏 pdb 和 ipdb 行为,正如我所描述的:
删除或注释这些行修复了问题,谢谢。
I found out that another programmer had added this to the beginning of the views file, this breaks pdb and ipdb behaviour, as I described:
Removing or commenting these lines fixed the issue, thanks.
通常,如果文件中包含非 ASCII 字符(可能在注释或字符串中),则会出现该错误。
如果你尝试在没有 ipdb/pdb 的情况下打开它,Django 将显示回溯
Usually, that error shows up if you have non-ascii characters in your file (mabe in a comment or a string).
If you try to open it without ipdb/pdb Django will display a traceback