Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SMTPHandler in the logging module fails with unicode strings #69597

Closed
simon04 mannequin opened this issue Oct 15, 2015 · 4 comments
Closed

SMTPHandler in the logging module fails with unicode strings #69597

simon04 mannequin opened this issue Oct 15, 2015 · 4 comments

Comments

@simon04
Copy link
Mannequin

simon04 mannequin commented Oct 15, 2015

BPO 25411
Nosy @vsajip, @bitdancer, @simon04
Files
  • SMTPHandler-unicode-v1.patch
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2015-10-17.15:24:37.055>
    created_at = <Date 2015-10-15.13:02:06.056>
    labels = []
    title = 'SMTPHandler in the logging module fails with unicode strings'
    updated_at = <Date 2015-10-17.15:24:37.053>
    user = 'https://github.com/simon04'

    bugs.python.org fields:

    activity = <Date 2015-10-17.15:24:37.053>
    actor = 'python-dev'
    assignee = 'none'
    closed = True
    closed_date = <Date 2015-10-17.15:24:37.055>
    closer = 'python-dev'
    components = []
    creation = <Date 2015-10-15.13:02:06.056>
    creator = 'simon04'
    dependencies = []
    files = ['40787']
    hgrepos = []
    issue_num = 25411
    keywords = ['patch']
    message_count = 4.0
    messages = ['253043', '253045', '253127', '253131']
    nosy_count = 4.0
    nosy_names = ['vinay.sajip', 'r.david.murray', 'python-dev', 'simon04']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = None
    url = 'https://bugs.python.org/issue25411'
    versions = ['Python 3.4', 'Python 3.5', 'Python 3.6']

    @simon04
    Copy link
    Mannequin Author

    simon04 mannequin commented Oct 15, 2015

    This relates to the unresolved bpo-9208 (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="from@free.fr", toaddrs="to@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 <module>
        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.

    @bitdancer
    Copy link
    Member

    This mostly looks good to me, Vinay.

    Simon: did you intentionally omit the date header, and if so why? (The smtp server normally adds one, but you can't really depend on that). Adding it would look like:

    msg['Date'] = email.utils.localtime()

    (Hmm. I wonder if send_message should add Date header if there isn't one...)

    @simon04
    Copy link
    Mannequin Author

    simon04 mannequin commented Oct 17, 2015

    I omitted the date header w/o intent. Basically because I couldn't quickly figure out how to set it.

    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Oct 17, 2015

    New changeset eb843115e052 by Vinay Sajip in branch '3.4':
    Closes bpo-25411: Improved Unicode support in SMTPHandler.
    https://hg.python.org/cpython/rev/eb843115e052

    New changeset b99b3ddd0ac4 by Vinay Sajip in branch '3.5':
    Closes bpo-25411: Merged fix from 3.4.
    https://hg.python.org/cpython/rev/b99b3ddd0ac4

    New changeset 522b5cdffd42 by Vinay Sajip in branch 'default':
    Closes bpo-25411: Merged fix from 3.5.
    https://hg.python.org/cpython/rev/522b5cdffd42

    @python-dev python-dev mannequin closed this as completed Oct 17, 2015
    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    None yet
    Projects
    None yet
    Development

    No branches or pull requests

    1 participant