SMTPHandler and Unicode
norbert
ncauderan at gmail.com
Mon Jul 5 16:49:40 EDT 2010
> > Ouch. Implicit encoding sounds like a bad behaviour.
Looking at the FileHandler source (
http://svn.python.org/view/python/trunk/Lib/logging/__init__.py?view=markup
) : the utf-8 encoding is a fallback. But *FileHandler family let you
specify the encoding you want, so that's OK I think.
But SMTPHandler does not have such a thing it sends its email with :
msg = "From: %s\r\nTo: %s\r\nSubject: %s\r\nDate: %s\r\n\r\n%s" % (
self.fromaddr,
",".join(self.toaddrs),
self.getSubject(record),
formatdate(), msg)
...
smtp.sendmail(from,to,msg)
And there is no encoding in all this.
It seems pretty dangerous to me (so my first post) because your
application will work without any problem with a FileHandler and the
day you'll decide to send email in case of serious problem, it will
crash with a UnicodeError. I can't see any workaround, except by
subclassing SMTPHandler's emit method to be unicode-aware or at least
URF-8 aware.
More information about the Python-list
mailing list