使用smtp时出现Hotmail SSL3版本号错误



我正在尝试使用python中的hotmail smtp服务器。然而,我的登录尝试导致了一个明显的SSL3版本号错误。我如何更改我正在使用的版本,以及我如何对此进行调查?

>> s.connect('smtp.live.com:587') 
(220,
 'BLU0-SMTP46.phx.gbl Microsoft ESMTP MAIL Service, Version: 6.0.3790.4675 ready at  Tue, 2 Jul 2013 12:15:57 -0700')
>> s.ehlo()
(250,
 'BLU0-SMTP46.phx.gbl Hello [123.456.789.01]nTURNnSIZE 41943040nETRNnPIPELININGnDSNnENHANCEDSTATUSCODESn8bitmimenBINARYMIMEnCHUNKINGnVRFYnTLSnSTARTTLSnOK')
 s.starttls()
(220, '2.0.0 SMTP server ready')
>> s.login('my.email@hotmail.com','MyPaSsW0rD')
---------------------------------------------------------------------------
SMTPServerDisconnected                    Traceback (most recent call last)
<ipython-input-48-c8e9d7577d8d> in <module>()
----> 1 s.login('mymemail@hotmail.com','myPassw0rd')
/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/smtplib.pyc in login(self, user, password)
    600         elif authmethod == AUTH_PLAIN:
    601             (code, resp) = self.docmd("AUTH",
--> 602                 AUTH_PLAIN + " " + encode_plain(user, password))
    603         elif authmethod == AUTH_LOGIN:
    604             (code, resp) = self.docmd("AUTH",
/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/smtplib.pyc in docmd(self, cmd, args)
    384         """Send a command, and return its response code."""
    385         self.putcmd(cmd, args)
--> 386         return self.getreply()
    387 
    388     # std smtp commands
/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/smtplib.pyc in getreply(self)
    357                 self.close()
    358                 raise SMTPServerDisconnected("Connection unexpectedly closed: "
--> 359                                              + str(e))
    360             if line == '':
    361                 self.close()
SMTPServerDisconnected: Connection unexpectedly closed: [Errno 1] _ssl.c:1363: error:1408F10B:SSL routines:SSL3_GET_RECORD:wrong version number

我的SSL版本:

>> import _ssl
>> print _ssl.OPENSSL_VERSION
OpenSSL 1.0.1e 11 Feb 2013

也许这是相关的:Python Smtp SSL在linux上的错误版本

我可以用Python 2.7.3复制Debian Wheezy的问题,它使用与您报告的OpenSSL版本完全相同的版本。我用Wireshark捕获了数据包,成功地进行了TLS握手,并交换了一些数据。然而,在那之后不久,客户端对服务器发送的内容感到不满,并关闭了连接。

我能够通过使用SSL3而不是TLS来解决这个问题。我不知道如何在Python中修补库方法,这样其他使用它的库就会有不同的行为,所以我只制作了smtplib的本地副本。

我复制了smtplib的2.7版本(点击原始链接下载),并更改了一行:

        self.sock = ssl.wrap_socket(self.sock, keyfile, certfile)

        self.sock = ssl.wrap_socket(self.sock, keyfile, certfile, ssl_version=ssl.PROTOCOL_SSLv3)

然后在我的本地目录中编辑文件,我得到:

Python 2.7.3 (default, Jan  2 2013, 13:56:14) 
[GCC 4.7.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import smtplib
>>> s = smtplib.SMTP()
>>> s.connect('smtp.live.com:587') 
(220, 'BLU0-SMTP418.blu0.hotmail.com Microsoft ESMTP MAIL Service, Version: 6.0.3790.4675 ready at  Wed, 3 Jul 2013 09:59:32 -0700')
>>> s.ehlo()
(250, 'BLU0-SMTP418.blu0.hotmail.com Hello [24.143.227.254]nTURNnSIZE 41943040nETRNnPIPELININGnDSNnENHANCEDSTATUSCODESn8bitmimenBINARYMIMEnCHUNKINGnVRFYnTLSnSTARTTLSnOK')
>>> s.starttls()
(220, '2.0.0 SMTP server ready')
>>> s.ehlo()
(250, 'BLU0-SMTP418.blu0.hotmail.com Hello [24.143.227.254]nTURNnSIZE 41943040nETRNnPIPELININGnDSNnENHANCEDSTATUSCODESn8bitmimenBINARYMIMEnCHUNKINGnVRFYnAUTH LOGIN PLAINnOK')
>>> s.login('my.email@hotmail.com','MyPaSsW0rD')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "smtplib.py", line 615, in login
    raise SMTPAuthenticationError(code, resp)
smtplib.SMTPAuthenticationError: (535, '5.0.0 Authentication Failed')
>>> 

我没有有效的Hotmail帐户,因此无法通过此处,但不再存在SSL错误。

相关内容

  • 没有找到相关文章

最新更新