Django UnicodeDecodeError when using pdb

ぃ、小莉子 提交于 2020-01-14 19:38:05

问题


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 :)


回答1:


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:

import sys, codecs
sys.stdout = codecs.getwriter('utf-8')(sys.stdout)

Removing or commenting these lines fixed the issue, thanks.




回答2:


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



来源:https://stackoverflow.com/questions/3741378/django-unicodedecodeerror-when-using-pdb

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!