Python3 SMTP ValueError:server_hostname 不能为空字符串或以前导点开头

2024-01-30

import smtplib
smtp = smtplib.SMTP()
smtp.connect('smtp.gmail.com','587')
(220, b'smtp.gmail.com ESMTP h15-v6sm187291iog.48 - gsmtp')
smtp.starttls()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/Cellar/python/3.7.0/Frameworks/Python.framework/Versions/3.7/lib/python3.7/smtplib.py", line 771, in starttls
    server_hostname=self._host)
  File "/usr/local/Cellar/python/3.7.0/Frameworks/Python.framework/Versions/3.7/lib/python3.7/ssl.py", line 412, in wrap_socket
    session=session
  File "/usr/local/Cellar/python/3.7.0/Frameworks/Python.framework/Versions/3.7/lib/python3.7/ssl.py", line 843, in _create
    owner=self, session=self._session,
ValueError: server_hostname cannot be an empty string or start with a leading dot.

我在 Mac 上使用 python 3.7,无法与 gmail 执行 tls 握手。此代码适用于 python 2.7,并且适用于使用 python 3.5.2 的 Ubuntu 服务器。有谁知道可能导致此错误的原因是什么?


好像是python3.7bug https://github.com/ansible/ansible/pull/44552,将主机名传递给 smtplib.SMTP 将修复它

smtp = smtplib.SMTP('smtp.gmail.com')
smtp.connect('smtp.gmail.com','587')
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Python3 SMTP ValueError:server_hostname 不能为空字符串或以前导点开头 的相关文章

随机推荐