This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: smtplib.LMTP.connect() raises TypeError if `timeout` is not specified
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.10, Python 3.9
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: corona10, trrhodes, vstinner, wuestengecko
Priority: normal Keywords: patch

Created on 2020-12-27 13:11 by wuestengecko, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 23969 merged trrhodes, 2020-12-27 21:20
PR 24050 merged trrhodes, 2021-01-01 17:30
Messages (8)
msg383850 - (view) Author: Wüstengecko (wuestengecko) Date: 2020-12-27 13:11
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.
msg383867 - (view) Author: Ross Rhodes (trrhodes) * Date: 2020-12-27 21:24
Hello Wüstengecko,

Thanks for raising this issue. I've opened a PR which I believe will resolve the problem, but it's difficult to verify this against the mock socket setup. Feel free to leave feedback.
msg384011 - (view) Author: Wüstengecko (wuestengecko) Date: 2020-12-29 15:08
Hello,
I can confirm that the PR resolves the issue.
Thanks for the quick fix!
msg384152 - (view) Author: Dong-hee Na (corona10) * (Python committer) Date: 2021-01-01 06:38
This
msg384153 - (view) Author: Dong-hee Na (corona10) * (Python committer) Date: 2021-01-01 06:38
This is a regression bug that should be fixed.
msg384186 - (view) Author: Dong-hee Na (corona10) * (Python committer) Date: 2021-01-01 17:20
New changeset 3bf05327c2b25d42b92795d9d280288c22a0963d by Ross in branch 'master':
bpo-42756: Configure LMTP Unix-domain socket to use global default timeout when timeout not provided (GH-23969)
https://github.com/python/cpython/commit/3bf05327c2b25d42b92795d9d280288c22a0963d
msg384214 - (view) Author: Dong-hee Na (corona10) * (Python committer) Date: 2021-01-02 03:44
New changeset 69120613c071e9327a9dc6e4b1ff21b2e94d885e by Ross in branch '3.9':
[3.9] bpo-42756: Configure LMTP Unix-domain socket to use global default timeout when timeout not provided (GH-23969) (GH-24050)
https://github.com/python/cpython/commit/69120613c071e9327a9dc6e4b1ff21b2e94d885e
msg384215 - (view) Author: Dong-hee Na (corona10) * (Python committer) Date: 2021-01-02 03:48
Thanks, Ross Rhodes for the fix!
And thanks, Wüstengecko for the report!
History
Date User Action Args
2022-04-11 14:59:39adminsetgithub: 86922
2021-01-02 03:48:39corona10setstatus: open -> closed
resolution: fixed
messages: + msg384215

stage: patch review -> resolved
2021-01-02 03:44:12corona10setmessages: + msg384214
2021-01-01 17:30:55trrhodessetpull_requests: + pull_request22886
2021-01-01 17:24:55corona10setpull_requests: - pull_request22885
2021-01-01 17:23:15corona10setpull_requests: + pull_request22885
2021-01-01 17:20:33corona10setmessages: + msg384186
2021-01-01 06:38:58corona10settype: crash -> behavior
2021-01-01 06:38:38corona10setmessages: + msg384153
2021-01-01 06:38:21corona10setmessages: + msg384152
versions: + Python 3.10
2021-01-01 06:26:51corona10setnosy: + vstinner
2021-01-01 06:23:58corona10setnosy: + corona10
2020-12-29 15:08:41wuestengeckosetmessages: + msg384011
2020-12-27 21:24:46trrhodessetmessages: + msg383867
2020-12-27 21:20:22trrhodessetkeywords: + patch
nosy: + trrhodes

pull_requests: + pull_request22814
stage: patch review
2020-12-27 13:11:53wuestengeckocreate