requester.py 文件源码

python
阅读 17 收藏 0 点赞 0 评论 0

项目:pnu 作者: erasaur 项目源码 文件源码
def reconnect(self):
        auth_attempts = 0

        while auth_attempts <= constants.MAX_RECONNECT_RETRIES:
            auth_attempts += 1

            try:
                self.mail = imaplib.IMAP4_SSL(pub_config['gmail']['imap'])
                u, data = self.mail.login(private_config['gmail']['username'],
                                          private_config['gmail']['password'])
                return
            except imaplib.IMAP4.error as e:
                logging.error("Login to retrieve emails failed!")
                logging.error(e)

            except Exception as e:
                logging.error("Error from IMAP! Trying to reconnect...")
                logging.error(e)

            time.sleep(constants.SMTP_RECONNECT_SLEEP_TIME)

        if auth_attempts > constants.MAX_RECONNECT_RETRIES:
            from pnu.outbound.alerter import smtp
            logging.critical("Could not connect to IMAP handler")
            smtp.send_error("Could not connect to IMAP handler")
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号