[issue42756] smtplib.LMTP.connect() raises TypeError if `timeout` is not specified

Wüstengecko report at bugs.python.org
Sun Dec 27 08:11:53 EST 2020


New submission from Wüstengecko <lemmi59612 at gmail.com>:

Since Python 3.9, calling `smtplib.LMTP.connect()` without explicitly specifying any `timeout=` raises a `TypeError`. Specifying `None` or any integer value works correctly.

```
>>> import smtplib
>>> smtplib.LMTP("/tmp/lmtp.sock")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python3.9/smtplib.py", line 1071, in __init__
    super().__init__(host, port, local_hostname=local_hostname,
  File "/usr/lib/python3.9/smtplib.py", line 253, in __init__
    (code, msg) = self.connect(host, port)
  File "/usr/lib/python3.9/smtplib.py", line 1085, in connect
    self.sock.settimeout(self.timeout)
TypeError: an integer is required (got type object)
>>> l = smtplib.LMTP()
>>> l.connect("/tmp/lmtp.sock")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python3.9/smtplib.py", line 1085, in connect
    self.sock.settimeout(self.timeout)
TypeError: an integer is required (got type object)
```

Upon investigation with `pdb`, the default object for the `timeout` parameter (`socket._GLOBAL_DEFAULT_TIMEOUT`) is passed through to the `self.sock.settimeout` call, instead of being handled as "no timeout specified". The relevant changes were introduced as fix for bpo-39329.

----------
components: Library (Lib)
messages: 383850
nosy: wuestengecko
priority: normal
severity: normal
status: open
title: smtplib.LMTP.connect() raises TypeError if `timeout` is not specified
type: crash
versions: Python 3.9

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue42756>
_______________________________________


More information about the Python-bugs-list mailing list