Cannot connect to IMAP server in Python 3.2

Steve Howell showell30 at yahoo.com
Thu Apr 5 01:13:55 EDT 2012


On Apr 4, 9:49 pm, Steven D'Aprano <steve
+comp.lang.pyt... at pearwood.info> wrote:
> I can connect to an IMAP server using Python 2.6:
>
> steve at runes:~$ python2.6
> Python 2.6.6 (r266:84292, Dec 27 2010, 00:02:40)
> [GCC 4.4.5] on linux2
> Type "help", "copyright", "credits" or "license" for more information.>>> import imaplib
> >>> server = imaplib.IMAP4_SSL('xxxxx')
> >>> print server
>
> <imaplib.IMAP4_SSL instance at 0xb7183c4c>
>
> But when I try with Python 3.2, it just sits there until it times out:
>
> steve at runes:~$ python3.2
> Python 3.2.2 (default, Feb 29 2012, 18:11:33)
> [GCC 4.4.5] on linux2
> Type "help", "copyright", "credits" or "license" for more information.>>> import imaplib
> >>> server = imaplib.IMAP4('xxxxx', imaplib.IMAP4_SSL_PORT)
>
> Traceback (most recent call last):
> [...]
> socket.timeout: timed out
>
> What am I doing wrong?
>

Is it simply the wrong port?  (IMAP4_SSL_PORT vs. IMAP4_PORT)

How long do you wait before seeing the timeout?

Have you tried print-debugging within your local copy of imaplib.py?
The code related to making the connection just wraps
socket.create_connection:


   234
   235     def _create_socket(self):
   236         return socket.create_connection((self.host, self.port))
   237
   238     def open(self, host = '', port = IMAP4_PORT):
   239         """Setup connection to remote server on "host:port"
   240             (default: localhost:standard IMAP4 port).
   241         This connection will be used by the routines:
   242             read, readline, send, shutdown.
   243         """
   244         self.host = host
   245         self.port = port
   246         self.sock = self._create_socket()
   247         self.file = self.sock.makefile('rb')


http://hg.python.org/cpython/file/3.2/Lib/imaplib.py



More information about the Python-list mailing list