[issue9208] SMTPHandler in the logging module does not handle unicode strings
simon04 added the comment: I don't see why/how this should be fixed in Python 3. Using the example from msg109621 and Python 3.5.0, I get: --- Logging error --- Traceback (most recent call last): File "/usr/lib/python3.5/logging/handlers.py", line 985, in emit smtp.sendmail(self.fromaddr, self.toaddrs, msg) File "/usr/lib/python3.5/smtplib.py", line 846, in sendmail msg = _fix_eols(msg).encode('ascii') UnicodeEncodeError: 'ascii' codec can't encode character '\xe9' in position 108: ordinal not in range(128) Call stack: File "/tmp/x.py", line 8, in LOG.error(u"accentu\u00E9") Message: 'accentué' Arguments: () The problem is that an SMTP message is constructed and non-ASCII characters are not escaped in SMTPHandler.emit. A robust fix would be to use email.mime.text .MIMEText instead: msg = MIMEText (msg) msg['Subject'] = self.getSubject(record) msg['From'] = self.fromaddr msg['To'] = ",".join(self.toaddrs) -- nosy: +simon04 ___ Python tracker <http://bugs.python.org/issue9208> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue25411] SMTPHandler in the logging module fails with unicode strings
New submission from simon04: This relates to the unresolved issue9208 (Python 2). SMTPHandler fails when receiving unicode strings. Example (from msg109621): import logging,logging.handlers smtpHandler = logging.handlers.SMTPHandler( mailhost=("smtp.free.fr",25), fromaddr="f...@free.fr", toaddrs="t...@free.fr", subject=u"error message") LOG = logging.getLogger() LOG.addHandler(smtpHandler) LOG.error(u"accentu\u00E9") … fails: --- Logging error --- Traceback (most recent call last): File "/usr/lib/python3.5/logging/handlers.py", line 985, in emit smtp.sendmail(self.fromaddr, self.toaddrs, msg) File "/usr/lib/python3.5/smtplib.py", line 846, in sendmail msg = _fix_eols(msg).encode('ascii') UnicodeEncodeError: 'ascii' codec can't encode character '\xe9' in position 108: ordinal not in range(128) Call stack: File "/tmp/x.py", line 8, in LOG.error(u"accentu\u00E9") Message: 'accentué' Arguments: () As discussed in msg252928 and msg252931, EmailMessage/send_message should be used instead to resolve this issue. Patch attached. -- files: SMTPHandler-unicode-v1.patch keywords: patch messages: 253043 nosy: simon04 priority: normal severity: normal status: open title: SMTPHandler in the logging module fails with unicode strings versions: Python 3.4, Python 3.5, Python 3.6 Added file: http://bugs.python.org/file40787/SMTPHandler-unicode-v1.patch ___ Python tracker <http://bugs.python.org/issue25411> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue25411] SMTPHandler in the logging module fails with unicode strings
Changes by simon04 : -- nosy: +r.david.murray ___ Python tracker <http://bugs.python.org/issue25411> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue25411] SMTPHandler in the logging module fails with unicode strings
simon04 added the comment: I omitted the date header w/o intent. Basically because I couldn't quickly figure out how to set it. -- ___ Python tracker <http://bugs.python.org/issue25411> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com