Hotmail SSL3 version number error using smtp

后端 未结 1 1159
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-19 18:58

I am trying to use the hotmail smtp server from python. However, my login attempt gives rise to an apparent SSL3 version number error. How can I change the version I am usin

1条回答
  •  醉梦人生
    2020-12-19 19:38

    I can duplicate your problem with Debian Wheezy with Python 2.7.3 which uses the exact same OpenSSL version you report. I captured packets with Wireshark and there is a successful TLS handshake and some data is exchanged. Shortly after that however, the client end gets unhappy with something the server sends and closes the connection.

    I was able to work around the issue by using SSL3 instead of TLS. I couldn't figure out how to patch a library method in Python so that other libraries that used it would behave differently, so I just made my own local copy of smtplib.

    I copied the 2.7 version of smtplib (click on the raw link to download) and changed one line:

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

    to

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

    Then with the edited file in my local directory I get:

    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]\nTURN\nSIZE 41943040\nETRN\nPIPELINING\nDSN\nENHANCEDSTATUSCODES\n8bitmime\nBINARYMIME\nCHUNKING\nVRFY\nTLS\nSTARTTLS\nOK')
    >>> s.starttls()
    (220, '2.0.0 SMTP server ready')
    >>> s.ehlo()
    (250, 'BLU0-SMTP418.blu0.hotmail.com Hello [24.143.227.254]\nTURN\nSIZE 41943040\nETRN\nPIPELINING\nDSN\nENHANCEDSTATUSCODES\n8bitmime\nBINARYMIME\nCHUNKING\nVRFY\nAUTH LOGIN PLAIN\nOK')
    >>> s.login('my.email@hotmail.com','MyPaSsW0rD')
    Traceback (most recent call last):
      File "", line 1, in 
      File "smtplib.py", line 615, in login
        raise SMTPAuthenticationError(code, resp)
    smtplib.SMTPAuthenticationError: (535, '5.0.0 Authentication Failed')
    >>> 
    

    I don't have a valid Hotmail account so I can't get past here, but there is no longer an SSL error.

    0 讨论(0)
提交回复
热议问题