Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django UnicodeDecodeError when using pdb

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

like image 861
maraujop Avatar asked Jul 22 '26 22:07

maraujop


1 Answers

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.

like image 99
maraujop Avatar answered Jul 25 '26 13:07

maraujop



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!