Opened 10 years ago

Closed 10 years ago

#3368 defect closed duplicate (duplicate)

twisted.python.log can't encode unicode correctly

Reported by: victorlin Owned by:
Priority: low Milestone:
Component: core Keywords: logging
Cc: Branch:


I encounter a problem. Once I send unicode message to log.msg or stdout (replaced by a proxy class), I got a UnicodeEncodeError: 'ascii' error. I try to use the patch in ticket #1990, but it does not work. There is no problem to display unicode in console of pydev (a python plug of eclipse), but it throw unicode encode exception in cmd of windows. I think the problem is that it should encode the unicode with 'cp950' on my computer's console environment, but it try to encode everything to 'ascii'. Could you fix this problem? My program Can't work around because this encoding problem. Thanks.

# this is the code to show the problem
# I have no idea does this problem occur in ascii environment
# But it occurs on my computer : Traditional Chinese Windows's cmd

from twisted.python import log

import sys

from twisted.python.logfile import DailyLogFile
log.startLogging(DailyLogFile('log', '.'))

print u'中文'

Change History (3)

comment:1 Changed 10 years ago by Itamar Turner-Trauring

Keywords: logging added; log unicode encoding problem removed
Priority: normallow

Why not write your own logging wrapper around Twisted's?

from twisted.python import log
import sys

def mylogmsg(s):

comment:2 Changed 10 years ago by Jean-Paul Calderone

Resolution: duplicate
Status: newclosed

Duplicate of #1990 and #989.

comment:3 Changed 8 years ago by <automation>

Owner: Glyph deleted
Note: See TracTickets for help on using tickets.