From ab6670b3af31c4c5ff72da1e35b56441c36e13de Mon Sep 17 00:00:00 2001 From: lanvent Date: Sat, 25 Mar 2023 13:10:51 +0800 Subject: [PATCH] fix: request qrscan when hotreload failed --- channel/wechat/wechat_channel.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/channel/wechat/wechat_channel.py b/channel/wechat/wechat_channel.py index 58b6f8d..dfa122c 100644 --- a/channel/wechat/wechat_channel.py +++ b/channel/wechat/wechat_channel.py @@ -4,6 +4,7 @@ wechat channel """ +import os import itchat import json from itchat.content import * @@ -51,8 +52,17 @@ class WechatChannel(Channel): def startup(self): # login by scan QRCode - itchat.auto_login(enableCmdQR=2, hotReload=conf().get('hot_reload', False)) - + hotReload = conf().get('hot_reload', False) + try: + itchat.auto_login(enableCmdQR=2, hotReload=hotReload) + except Exception as e: + if hotReload: + logger.error("Hot reload failed, try to login without hot reload") + itchat.logout() + os.remove("itchat.pkl") + itchat.auto_login(enableCmdQR=2, hotReload=hotReload) + else: + raise e # start message listener itchat.run()