Skip to content

logging issue #439

@CamielBouchier

Description

@CamielBouchier

Hi there, thanks for a great lib!

When starting to play with it I encountered an issue: when intentionally introducing an error (here absence of starttls on an account that needs it), he logging of your module flips. Generating long and iterated logs about logging errors, such as:

TypeError: not all arguments converted during string formatting
Call stack:
  File "cb_mail.py", line 333, in <module>
    rv = QApplication.instance().exec_()
  File "cb_mail.py", line 259, in cb_on_account_login
    self.an_account.cb_login()
  File "D:\Software_MyDevelopment\Active\cb_mail\cb_account.py", line 162, in cb_login
    login_function()
  File "D:\Software_MyDevelopment\Active\cb_mail\cb_account.py", line 159, in login_function
    self.settings["password"])
  File "C:\Python37\lib\site-packages\imapclient\imapclient.py", line 379, in login
    unpack=True,
  File "C:\Python37\lib\site-packages\imapclient\imapclient.py", line 1707, in _command_and_check
    typ, data = meth(*args)
  File "C:\Python37\lib\imaplib.py", line 596, in login
    typ, dat = self._simple_command('LOGIN', user, self._quote(password))
  File "C:\Python37\lib\imaplib.py", line 1196, in _simple_command
    return self._command_complete(name, self._command(name, *args))
  File "C:\Python37\lib\imaplib.py", line 1019, in _command_complete
    typ, data = self._get_tagged_response(tag)
  File "C:\Python37\lib\imaplib.py", line 1143, in _get_tagged_response
    self.print_log()
  File "C:\Python37\lib\imaplib.py", line 1240, in print_log
    self._mesg(*self._cmd_log[i])

I don't think it matters, but this was the code:

def cb_login(self) :

        logger.info(f"cb_account.cb_login")

        def login_function() :

            self.server = IMAPClient(host    = self.settings["imap_server"],
                                     port    = self.settings["imap_port"],
                                     use_uid = True,
                                     ssl     = self.settings["imap_ssl"],
                                     timeout = self.settings["timeout"])

            #if self.settings["imap_starttls"] :
            #    rv = self.server.starttls()
            #    logger.info(f"{self.account_identifier} {rv}")

            rv = self.server.login(self.settings["username"],
                                   self.settings["password"])
            logger.info(f"{self.account_identifier} {rv}")

        login_function()
        #worker = cb_account_worker(login_function)
        #worker.signals.signal_error.connect(self.cb_on_login_error)
        #worker.signals.signal_result.connect(self.cb_on_login_completed)
        #self.threadpool.start(worker)

My current workaround is selectively disabling logging:

imapclient_log = logging.getLogger("imapclient")
imapclient_log.setLevel(logging.INFO)

You might want to review,

Camiel B.

Metadata

Metadata

Assignees

Labels

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions