Simple unicode-safe version of str(exception)?

Bjoern Schliessmann usenet-mail-0306.20.chr0n0ss at spamgourmet.com
Mon Apr 28 16:02:22 EDT 2008


Russell E. Owen wrote:

> I have code like this:
> except Exception, e:
>    self.setState(self.Failed, str(e))
> which fails if the exception contains a unicode argument.

Fails how?
 
> I did, of course, try unicode(e) but that fails.

Converting unicode to unicode doesn't help. Instead of just e, try
using e.encode("some-encoding") where some-encoding should be your
system's default encoding like utf-8 or iso8859-1.

Regards,


Björn

-- 
BOFH excuse #434:

Please state the nature of the technical emergency




More information about the Python-list mailing list