Hello all,
I am developing an application for use in my organization. In porting from a development server to a production server, I’ve run into problems using smtplib. The development server, which is running Ubuntu 18.04 and natively uses Python 3.6, works fine. The production server is running Debian Bullseye (the current testing distribution), which is shipped with Python 3.7. The issue is with the portion of the script that connects to my enterprise email server for the purpose of sending email notifications. The server, which is running Microsoft Exchange, requires authentication to access; which I initiate via a smtplib.starttls() call in the script.
On the development server, I am able to authenticate with the Microsoft Exchange server.
On the production server, I receive the following trace:
Traceback (most recent call last):
File "./notify.py", line 470, in <module>
server.starttls ()
File "/usr/lib/python3.7/smtplib.py", line 771, in starttls
server_hostname=self._host)
File "/usr/lib/python3.7/ssl.py", line 423, in wrap_socket
session=session
File "/usr/lib/python3.7/ssl.py", line 870, in _create
self.do_handshake()
File "/usr/lib/python3.7/ssl.py", line 1139, in do_handshake
self._sslobj.do_handshake()
OSError: [Errno 0] Error
Turning on SMTP logging doesn’t reveal anything unusual:
send: 'STARTTLS\r\n'
reply: b'220 2.0.0 SMTP server ready\r\n'
reply: retcode (220); Msg: b'2.0.0 SMTP server ready'
(The next line, after the above, forms the start of the traceback reported above.) Based on the above, it would not appear to be an issue with the server since the server is responding identically in each case.
I’ve done the following to troubleshoot the issue:
- Created new virtual machines for Ubuntu 18.04, Debian Stable, and Debian Testing
- Followed identical steps to install the dependencies for my script
If the virtual machine ships with Python 3.6, smtplib.starttls()
will succeed. If Python 3.7 is supplied by the distribution, smtplib.startls()
will produce the error above.
I have tried setting up a virtual environment to make isolating the issue easier, but I’m not greatly experienced with them. After compiling Python 3.6 from source and setting up a virtual environment with it, the environment was still importing the OS-supplied version of the ssl.py library (i.e., the one in /usr/lib/python3.7/ssl.py
). Presumably I need to separately download these library modules?
At this point I’m looking for advice on how best to isolate the issue so that I can either find a workaround, gain advice on how best to run a newer development version of Python to see if that solves the issue, or (if appropriate) file a bug report.