mjs / imapclient

An easy-to-use, Pythonic and complete IMAP client library
https://imapclient.readthedocs.io/
Other
516 stars 84 forks source link

Python 3.9 incompatible with Imapclient due to new timeout parameter in imaplib #442

Closed tomanizer closed 3 years ago

tomanizer commented 3 years ago

Using Imapclient in Python 3.9 raises on connect.

TypeError: open() takes 3 positional arguments but 4 were given.

This appears to be related to https://docs.python.org/3/library/imaplib.html Changed in version 3.9: The optional timeout parameter was added.

The error does not occur in Python <= 3.8.

In [10]: import ssl
    ...:
    ...: from imapclient import IMAPClient

In [11]: ssl
Out[11]: <module 'ssl' from 'C:\\Programs\\Miniconda3_x64\\envs\\reademails\\lib\\ssl.py'>

In [12]: ssl_context = ssl.create_default_context()

In [13]: ssl_context.check_hostname = False

In [14]: ssl_context.verify_mode = ssl.CERT_NONE

In [15]: server = IMAPClient(HOST, ssl_context=ssl_context)
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-15-d725fdfc50f8> in <module>
----> 1 server = IMAPClient(HOST, ssl_context=ssl_context)

C:\Programs\Miniconda3_x64\envs\reademails\lib\site-packages\imapclient\imapclient.py in __init__(self, host, port, use_uid, ssl, stream, ssl_context, timeout)
    192         self._idle_tag = None
    193
--> 194         self._imap = self._create_IMAP4()
    195         logger.debug("Connected to host %s over %s", self.host,
    196                      "SSL/TLS" if ssl else "plain text")

C:\Programs\Miniconda3_x64\envs\reademails\lib\site-packages\imapclient\imapclient.py in _create_IMAP4(self)
    226
    227         if self.ssl:
--> 228             return tls.IMAP4_TLS(self.host, self.port, self.ssl_context,
    229                                  self._timeout)
    230

C:\Programs\Miniconda3_x64\envs\reademails\lib\site-packages\imapclient\tls.py in __init__(self, host, port, ssl_context, timeout)
     42         self.ssl_context = ssl_context
     43         self._timeout = timeout
---> 44         imaplib.IMAP4.__init__(self, host, port)
     45
     46     def open(self, host, port):

C:\Programs\Miniconda3_x64\envs\reademails\lib\imaplib.py in __init__(self, host, port, timeout)
    200         # Open socket to server.
    201
--> 202         self.open(host, port, timeout)
    203
    204         try:

TypeError: open() takes 3 positional arguments but 4 were given
NicolasLM commented 3 years ago

Duplicate of #425

tomanizer commented 3 years ago

Thank you for pointing that out @NicolasLM

On further investigation, I noticed that conda installs old version 2.0.0 which still has the bug, whereas 2.2.0 on pypi has it fixed.

conda install imapclient https://anaconda.org/conda-forge/imapclient

Does version 2.2.0 need a new conda package and upload to anaconda repo and conda forge?

mjs commented 3 years ago

It would see that a newer conda package is required. I have no idea what the process is for that however as @NicolasLM and I don't have anything to do with the conda package.