Bladeren bron

fix: request qrscan when hotreload failed

lanvent 3 jaren geleden
bovenliggende
commit
ab6670b3af
1 gewijzigde bestanden met toevoegingen van 12 en 2 verwijderingen
  1. 12 2
      channel/wechat/wechat_channel.py

+ 12 - 2
channel/wechat/wechat_channel.py

@@ -4,6 +4,7 @@
 wechat channel
 wechat channel
 """
 """
 
 
+import os
 import itchat
 import itchat
 import json
 import json
 from itchat.content import *
 from itchat.content import *
@@ -51,8 +52,17 @@ class WechatChannel(Channel):
 
 
     def startup(self):
     def startup(self):
         # login by scan QRCode
         # 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
         # start message listener
         itchat.run()
         itchat.run()