A few days back imaplib2 simply stopped working: immediately after the class is instantiated, I get a socket error and the connection is closed, which makes login impossible. I am not aware of any changes in Python or the socket module.
Tested on Ubuntu MATE 17.10 i386 with python 3.6, 3.5 and 3.4 using the latest (3.05) version, using several IMAP mail providers.
import imaplib2
oImap = imaplib2.IMAP4_SSL('imap.gmail.com', 993, debug=4)
35:34.18 MainThread imaplib2 version 3.05
35:34.18 MainThread imaplib2 debug level 4, buffer level 3
35:34.34 MainThread connected to imap.gmail.com on port 993
35:34.34 imap.gmail.com writer starting
35:34.35 imap.gmail.com reader starting using poll
35:34.35 MainThread _request_push(continuation, welcome, {}) = b'CPNE0'
35:34.35 imap.gmail.com reader poll => [(13, 1)]
35:34.35 MainThread welcome:b'CPNE0'.ready.wait
35:34.35 imap.gmail.com reader rcvd 69
35:34.35 MainThread _close_threads
35:34.35 imap.gmail.com reader < b'* OK Gimap ready for requests from xxx\r\n'
35:34.35 imap.gmail.com writer finished
35:34.35 MainThread call shutdown
35:34.35 imap.gmail.com reader poll => [(13, 17)]
35:34.35 imap.gmail.com reader last 20 log messages:
35:34.34 imap.gmail.com writer starting
35:34.35 imap.gmail.com reader starting using poll
35:34.35 MainThread _close_threads
35:34.35 imap.gmail.com writer finished
35:34.35 MainThread call shutdown
35:34.35 imap.gmail.com reader socket error: <class 'ValueError'> - Read on closed or unwrapped SSL socket.
35:34.35 imap.gmail.com reader finished
35:34.45 imap.gmail.com handler starting
35:34.45 imap.gmail.com handler terminating: 'Terminated'
35:34.45 imap.gmail.com handler welcome:b'CPNE0'.ready.set
35:34.45 imap.gmail.com handler state_change_free.set
35:34.45 imap.gmail.com handler finished
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "xxx/imaplib2.py", line 2093, in __init__
IMAP4.__init__(self, host, port, debug, debug_file, identifier, timeout, debug_buf_lvl)
File "xxx/imaplib2.py", line 375, in __init__
self.welcome = self._request_push(name='welcome', tag='continuation').get_response('IMAP4 protocol error: %s')[1]
TypeError: 'NoneType' object is not subscriptable