diff -r c6e0c29913ec Lib/imaplib.py --- a/Lib/imaplib.py Thu Sep 03 15:35:33 2015 -0700 +++ b/Lib/imaplib.py Fri Sep 04 15:29:28 2015 +1200 @@ -273,7 +273,9 @@ def _create_socket(self): - return socket.create_connection((self.host, self.port)) + # Workaround for issue 18540: + host = None if str(self.host) == '' else self.host + return socket.create_connection((host, self.port)) def open(self, host = '', port = IMAP4_PORT): """Setup connection to remote server on "host:port" diff -r c6e0c29913ec Lib/test/test_imaplib.py --- a/Lib/test/test_imaplib.py Thu Sep 03 15:35:33 2015 -0700 +++ b/Lib/test/test_imaplib.py Fri Sep 04 15:29:28 2015 +1200 @@ -241,6 +241,17 @@ client.shutdown() @reap_threads + def test_issue18540(self): + # Test that the underlaying socket uses it's defaults if no arguments + # are given (instead of getting invalid arguments, see issue 18540). + try: + # Should succeed or raise a ConnectionRefusedError: + client = self.imap_class() + client.shutdown() + except ConnectionRefusedError: + pass + + @reap_threads def test_issue5949(self): class EOFHandler(socketserver.StreamRequestHandler):