imaplib: how to specify SSL/TLS protocol version?
Grant Edwards
invalid at invalid.invalid
Wed Apr 9 16:20:15 EDT 2014
On 2014-04-09, Grant Edwards <invalid at invalid.invalid> wrote:
> Connecting to Exchange server fails like this:
>
> File "/usr/lib64/python2.7/imaplib.py", line 1148, in __init__
> IMAP4.__init__(self, host, port)
> SSLError: [Errno 1] _ssl.c:1419: error:1408F10B:SSL routines:SSL3_GET_RECORD:wrong version number
>
> Experiments show that when calling ssl.wrap_socket() I have to specify
> ssl_version=PROTOCOL_TLSv1 to avoid the above error.
>
> How do I tell imaplib to use TLS1 instead of SSL3?
I'm not too keen on this approach, but monkey-patching the open()
method seems to work:
def my_imap4_ssl_open(self, host = '', port = 993):
self.host = host
self.port = port
self.sock = socket.create_connection((host, port))
self.sslobj = ssl.wrap_socket(self.sock, self.keyfile, self.certfile, ssl_version=ssl.PROTOCOL_TLSv1)
self.file = self.sslobj.makefile('rb')
imaplib.IMAP4_SSL.open = my_imap4_ssl_open
--
Grant Edwards grant.b.edwards Yow! I hope the
at ``Eurythmics'' practice
gmail.com birth control ...
More information about the Python-list
mailing list