Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

logging.handlers.SMTPHandler: secure argument is broken in Python 3.12+ #127712

Closed
Labels
3.12only security fixes3.13bugs and security fixes3.14bugs and security fixesstdlibStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or error
@s-hamann

Description

@s-hamann

Bug report

Bug description:

Thedocumentation forlogging.handlers.SMTPHandler describes thesecure argument as follows:

To specify the use of a secure protocol (TLS), pass in a tuple to thesecure argument. This will only be used when authentication credentials are supplied. The tuple should be either an empty tuple, or a single-value tuple with the name of a keyfile, or a 2-value tuple with the names of the keyfile and certificate file. (This tuple is passed to thesmtplib.SMTP.starttls() method.)

However, from Python 3.12 on, only the empty tuple actually works.
With a single-value-tuple or a two-value-tuple,smtplib.SMTP.starttls() throws an exception like this:

Traceback (most recent call last):  File "/usr/lib/python3.13/logging/handlers.py", line 1097, in emit    smtp.starttls(*self.secure)    ~~~~~~~~~~~~~^^^^^^^^^^^^^^TypeError: SMTP.starttls() takes 1 positional argument but 3 were given

The reason seems immediately obvious from the last sentence in the description of thesecure argument: The tuple is passed tosmtplib.SMTP.starttls().
Thedocumentation for this method states:

Changed in version 3.12: The deprecatedkeyfile andcertfile parameters have been removed.

SMTPHandler still relies on the these parameters.

Here's a minimal script to reproduce the error (requires a mocked SMTP server on port 1025):

#!/usr/bin/env python3importloggingfromlogging.handlersimportSMTPHandlerlogger=logging.getLogger()handler=SMTPHandler(mailhost=("localhost",1025),fromaddr="foo@localhost",toaddrs="bar@localhost",subject="Test",credentials=("foo","bar"),secure=("/path/to/private.key","/path/to/cert.pem"    ),)logger.addHandler(handler)logger.error("SMTPHandler is broken")

Note that Python 3.11 is not affected and the above code successfully attempts to issue a STARTTLS command.

CPython versions tested on:

3.11, 3.12, 3.13

Operating systems tested on:

Linux

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.12only security fixes3.13bugs and security fixes3.14bugs and security fixesstdlibStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or error

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp