- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
此问题与 smtplib 的 SMTP_SSL 连接有关。
当与 SMTP 连接时(没有 ssl),它正在工作。
在 SMTP_SSL 中尝试相同的主机和端口时,出现错误。该错误仅基于主机,gmail 设置也可以正常工作。
请检查以下示例,如果 outlook 和 office365 需要任何更改,请告诉我。
In [1]: import smtplib
In [10]: smtplib.SMTP_SSL('smtp.gmail.com', 465, timeout=100)
Out[10]: <smtplib.SMTP_SSL instance at 0x109ccaf38>
In [2]: smtplib.SMTP('smtp-mail.outlook.com', 587, timeout=100)
Out[1]: <smtplib.SMTP instance at 0x10a00bb90>
In [3]: smtplib.SMTP_SSL('smtp-mail.outlook.com', 587, timeout=100)
---------------------------------------------------------------------------
SSLError Traceback (most recent call last)
<ipython-input-9-f0c5b0de4e24> in <module>()
----> 1 smtplib.SMTP_SSL('smtp-mail.outlook.com', 587, timeout=100)
/python2.7/smtplib.pyc in __init__(self, host, port, local_hostname, keyfile, certfile, timeout)
794 self.keyfile = keyfile
795 self.certfile = certfile
--> 796 SMTP.__init__(self, host, port, local_hostname, timeout)
797
798 def _get_socket(self, host, port, timeout):
python2.7/smtplib.pyc in __init__(self, host, port, local_hostname, timeout)
254 self.esmtp_features = {}
255 if host:
--> 256 (code, msg) = self.connect(host, port)
257 if code != 220:
258 raise SMTPConnectError(code, msg)
python2.7/smtplib.pyc in connect(self, host, port)
314 if self.debuglevel > 0:
315 print>>stderr, 'connect:', (host, port)
--> 316 self.sock = self._get_socket(host, port, self.timeout)
317 (code, msg) = self.getreply()
318 if self.debuglevel > 0:
python2.7/smtplib.pyc in _get_socket(self, host, port, timeout)
800 print>>stderr, 'connect:', (host, port)
801 new_socket = socket.create_connection((host, port), timeout)
--> 802 new_socket = ssl.wrap_socket(new_socket, self.keyfile, self.certfile)
803 self.file = SSLFakeFile(new_socket)
804 return new_socket
python2.7/ssl.pyc in wrap_socket(sock, keyfile, certfile, server_side, cert_reqs, ssl_version, ca_certs, do_handshake_on_connect, suppress_ragged_eofs, ciphers)
909 do_handshake_on_connect=do_handshake_on_connect,
910 suppress_ragged_eofs=suppress_ragged_eofs,
--> 911 ciphers=ciphers)
912
913 # some utility functions
python2.7/ssl.pyc in __init__(self, sock, keyfile, certfile, server_side, cert_reqs, ssl_version, ca_certs, do_handshake_on_connect, family, type, proto, fileno, suppress_ragged_eofs, npn_protocols, ciphers, server_hostname, _context)
577 # non-blocking
578 raise ValueError("do_handshake_on_connect should not be specified for non-blocking sockets")
--> 579 self.do_handshake()
580
581 except (OSError, ValueError):
python2.7/ssl.pyc in do_handshake(self, block)
806 if timeout == 0.0 and block:
807 self.settimeout(None)
--> 808 self._sslobj.do_handshake()
809 finally:
810 self.settimeout(timeout)
SSLError: [SSL: UNKNOWN_PROTOCOL] unknown protocol (_ssl.c:590)
引用网址:https://docs.python.org/2/library/smtplib.html#smtplib.SMTP_SSL
最佳答案
我今天遇到了同样的问题,我已经解决了。
这是我的演示。
def _send_email(self, msg):
if self.smtp_port == 465:
server = smtplib.SMTP_SSL(self.smtp_host, self.smtp_port)
elif self.smtp_port == 587:
server = smtplib.SMTP(self.smtp_host, self.smtp_port)
server.starttls()
else:
raise Exception('port {} not support'.format(SMTP_PORT))
server.set_debuglevel(1)
server.login(self.from_addr, self.password)
server.sendmail(self.from_addr, [self.to_addr], msg.as_string())
server.quit()
个人看法(可能有误,个人理解,如有不妥,请大家指正,谢谢。):
465
和587
用于不同的协议(protocol)。前者使用SSL,后者使用TLS。它们都是在SMTP通信之前使用SSL加密我们的邮件内容。
但对于 587
。您必须先发送 STARTTLS
。如果你不这样做,你会收到这样的消息 Must issue a STARTTLS command first.
而对于 465
你不能使用 tls 命令
关于python - SMTP_SSL SSLError : [SSL: UNKNOWN_PROTOCOL] unknown protocol (_ssl. c:590),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44761676/
我想从源代码升级默认的python2.6.6到python2.7,我安装了: yum groupinstall "Development tools" yum install zlib-devel b
_ssl.sslwrap 函数似乎检查传入的 sock 是否是 _socket.socket 的子类。我正在传递一个实现 _socket.socket 接口(interface)的类。 它很生气,因为
带有 Python 2.7 的 Ubuntu Maverick: 我不知道如何解决以下导入错误: >>> import ssl Traceback (most recent call last):
问题 当我运行你的 python3 应用程序时,它显示 File "/usr/local/lib/python3.6/ssl.py", line 101, in import _ssl
Ubuntu Maverick w/Python 2.7: 我不知道如何解决以下导入错误: >>> import ssl Traceback (most recent call last): Fi
你知道这个错误吗: urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:600) 当我运行
环境:Ubuntu 10.04.4 长期支持版Python 3.4.3 我有一个可以在 Windows 上完美运行的 python 3.4 Flask HTTPS 服务器。我需要将它转移到现有的 Ub
Python3 exchangelib 连接错误:_ssl.c:749? 我正在尝试使用 exchangelib 连接到我公司的 Exchange 服务器。我想查看我在 MS Exchange/OWA
当我执行以下行时, req = urllib2.Request(requestwithtoken) self.response = urllib2.urlopen(req,self.request).
我正在尝试这样的简单查询(在 geopy documentation 中出现: from geopy.geocoders import Nominatim geolocator = Nominatim
尝试运行Discord机器人时,出现以下错误: raise ClientConnectorCertificateError( aiohttp.client_exceptions.ClientC
我正在尝试使用 SSL 在 Redhat 中构建 python 2.7。我已经取消注释 Modules/Setup.dist 中的行: SSL=/urs/local/ssl _ssl _ssl.c -
有什么区别 import ssl 和 import _ssl 我在不同的服务器上运行 python 代码。在某些服务器上,两者都适合我。在其他服务器上,只有第二个有效,第一个给了我以下内容: Impo
对于 python request.get 和 request.post 调用,我得到了 [SSL: CERTIFICATE_VERIFY_FAILED] 证书验证失败 (_ssl.c:646)。以前
我正在尝试在我的 Mac 上安装 nltk,但在按照以下说明操作后我不断收到此错误消息: 安装 NLTK:sudo pip install -U nltk 安装 Numpy(可选):sudo pip
如下配置和安装python2.7: ./configure --enable-shared --with-ssl make install 然后使用命令 python setup.py install
尝试使用 gcc (Debian 6.2.1-7) 6.2.1 20161215 编译 Python 3.4.3 时出现以下错误: Failed to build these modules: _ha
我通过将源代码安装到我的 RHEL4 盒子中来添加 python 2.7.13 作为 altinstall wget --no-check-certificate https://www.python
我一直在尝试使用以下方法安装 python 包: pip install 我得到的是: “警告:在连接被 'SSLError(SSLCertVerificationError(1,'[SSL: CE
我想通过 python 脚本发送邮件并使用批处理文件启动脚本。从批处理文件启动时,我收到错误“ImportError: DLL load failed while importing _ssl”,当直
我是一名优秀的程序员,十分优秀!