logging of strings with broken encoding

Peter Otten __peter__ at web.de
Thu Jul 2 17:16:29 CEST 2009


Thomas Guettler wrote:

> I have bug in my code, which results in the same error has this one:
> 
> https://bugs.launchpad.net/bzr/+bug/295653
> {{{
> Traceback (most recent call last):
>   File "/usr/lib/python2.6/logging/__init__.py", line 765, in emit
>     self.stream.write(fs % msg.encode("UTF-8"))
>   ..
> UnicodeDecodeError: 'ascii' codec can't decode byte 0xe4 in position 8:
> ordinal not in range(128) }}}
> 
> I run Python 2.6. In SVN the code is the same (StreamHandler ... def
> emit...):
> http://svn.python.org/view/python/branches/release26-
maint/Lib/logging/__init__.py?revision=72507&view=markup
> 
> I think msg.encode("UTF-8", 'backslashreplace') would be better here.
> 
> What do you think?

That won't help. It's a *decoding* error. You are feeding it a non-ascii 
byte string.

Peter




More information about the Python-list mailing list