Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork33.7k
Description
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 the
secureargument. 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 givenThe 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 deprecated
keyfileandcertfileparameters 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
Labels
Projects
Status