SMTPHandler and Unicode

norbert ncauderan at gmail.com
Mon Jul 5 06:07:16 EDT 2010


Hello,

I want to send error messages with SMTPHandler logging. But
SMTPHandler does not seem to be unicode aware. Is there something
doable without playing with sys.setdefaultencoding ?

import logging,logging.handlers
smtpHandler =
logging.handlers.SMTPHandler(mailhost=("smtp.example.com",25),
fromaddr="toto at example.com", toaddrs="toto at example.com",
subject=u"error message")

LOG = logging.getLogger()
LOG.addHandler(smtpHandler)

LOG.error(u"sans accent")
LOG.error(u"accentu\u00E9")

gives : UnicodeEncodeError: 'ascii' codec can't encode character
u'\xe9' in position 117: ordinal not in range(128)

Thank you !



More information about the Python-list mailing list