[Twisted-Python] print unicode

Pet petshmidt at googlemail.com
Wed May 5 10:15:51 EDT 2010


On Wed, May 5, 2010 at 2:49 PM, Itamar Turner-Trauring
<itamar at itamarst.org> wrote:
> On Wed, 2010-05-05 at 13:45 +0200, Pet wrote:
>> Hello!
>>
>> I'm using Twisted 10.0 and as usually sometime print debug infos with
>> myunicodestr.encode('UTF-8') which are saved to logfile, but since
>> using twisted 10 I'm getting
>>
>> UnicodeEncodeError: 'ascii' codec can't encode characters...
>>
>> type(myunicodestr) returns <type 'unicode'>
>>
>>
>> What is the problem here?
>
> This works fine for me (Twisted trunk):
>
> $ python2.5 -c "import sys; from twisted.python import log; \
> log.startLogging(file('/tmp/log', 'w')); print \
> u'\u1234'.encode('UTF-8')"
> $ cat /tmp/log
> 2010-05-05 08:48:40-0400 [-] Log opened.
> 2010-05-05 08:48:40-0400 [-] ሴ
>
> Can you include a minimal reproducing example?

If I print as you do it works, but my string is fetched from database
and only then it fails

>
>
> _______________________________________________
> Twisted-Python mailing list
> Twisted-Python at twistedmatrix.com
> http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python
>



More information about the Twisted-Python mailing list