Llamafu
Llamafu

Reputation: 21

imapClient error (diff version python and windows)

This question was asked by paul_h, but I'm too new to comment with (hopefully) relevant information. I'm having the same problem with imapClient, and it's obviously not Python/Windows version specific. Paul H is running Python 2.7.11 on win 10. imapclient error on Windows

I was running 3.4.3, and even upgraded to 3.5.1. on both win7, and even tried an old Vista machine.

import imapclient
imapObj = imapclient.IMAPClient('imap.gmail.com', ssl=True)

It returns:

Traceback (most recent call last):
  File "<pyshell#8>", line 1, in <module>
    imapObj = imapclient.IMAPClient('imap.gmail.com', ssl=True)
  File "C:\Python\lib\site-packages\imapclient\imapclient.py", line 152, in __init__
    self._imap = self._create_IMAP4()
  File "C:\Python\lib\site-packages\imapclient\imapclient.py", line 164, in _create_IMAP4
    self._timeout)
  File "C:\Python\lib\site-packages\imapclient\tls.py", line 153, in __init__
    imaplib.IMAP4.__init__(self, host, port)
  File "C:\Python\lib\imaplib.py", line 189, in __init__
    self.open(host, port)
  File "C:\Python\lib\site-packages\imapclient\tls.py", line 159, in open
    self.sock = wrap_socket(sock, self.ssl_context, host)
  File "C:\Python\lib\site-packages\imapclient\tls.py", line 126, in wrap_socket
    ssl_context = create_default_context()
  File "C:\Python\lib\site-packages\imapclient\tls.py", line 109, in create_default_context
    context.load_verify_locations(cadata=certs)
  File "C:\Python\lib\site-packages\backports\ssl\core.py", line 654, in load_verify_locations
    self._ctx.load_verify_locations(cafile, capath)
  File "C:\Python\lib\site-packages\OpenSSL\SSL.py", line 528, in load_verify_locations
    _raise_current_error()
  File "C:\Python\lib\site-packages\OpenSSL\_util.py", line 48, in exception_from_error_queue
    raise exception_type(errors)
OpenSSL.SSL.Error: []

Meanwhile the stock imaplib connects with ssl fine.

M = imaplib.IMAP4_SSL('imap.gmail.com')

And sorry about starting a new question, but I didn't want to post this as an answer.

Upvotes: 2

Views: 1841

Answers (2)

Sten
Sten

Reputation: 116

Here's a workaround that worked for me (Python 3.5, Windows 10):

from backports import ssl
from imapclient import IMAPClient

context = ssl.SSLContext(ssl.PROTOCOL_TLSv1_2)

imapObj = IMAPClient('imap.gmail.com', ssl=True, ssl_context=context)

The above code was derived from the developer's workaround here, but I found I only needed the one line defining context to make it work. Specifying other SSL/TLS protocols also worked.

Upvotes: 3

Robert Weathers
Robert Weathers

Reputation: 31

I had this problem as well , I was waiting for someone to answer this but took to long. We were using IMAPclient 1.0.1 and got this error , so workaround is to install imapclient 0.13

pip uninstall imapclient
pip install imapclient==0.13

Upvotes: 3

Related Questions