增加异常检测

master
ChenXuzheng 2022-05-10 15:37:41 +00:00
parent 141043febf
commit 01719e04d3
1 changed files with 164 additions and 148 deletions

22
main.py
View File

@ -1,3 +1,5 @@
from logging import error
from traceback import print_tb
import requests import requests
import re import re
import json import json
@ -211,9 +213,11 @@ class HealthCheckInHelper(ZJULogin):
return return
except: except:
print('验证码识别失败') print('验证码识别失败')
raise Exception("验证码识别失败")
except: except:
print('打卡网页获取失败') print('发生异常')
finally: raise Exception("发生异常")
new_info_tmp = json.loads(re.findall(r'def = ({[^\n]+})', html)[0]) new_info_tmp = json.loads(re.findall(r'def = ({[^\n]+})', html)[0])
new_id = new_info_tmp['id'] new_id = new_info_tmp['id']
new_uid = new_info_tmp['uid'] new_uid = new_info_tmp['uid']
@ -351,6 +355,11 @@ class HealthCheckInHelper(ZJULogin):
if self.delay_run: if self.delay_run:
# 确保定时脚本执行时间不太一致 # 确保定时脚本执行时间不太一致
time.sleep(random.randint(10, 100)) time.sleep(random.randint(10, 100))
try_count=0
while True:
if try_count>10:
print("已经尝试你妈的10次了还不对你退群吧")
return
try: try:
self.login() self.login()
# 拿取eai-sess的cookies信息 # 拿取eai-sess的cookies信息
@ -363,9 +372,16 @@ class HealthCheckInHelper(ZJULogin):
# print(geo_info) # print(geo_info)
res = self.take_in(geo_info) res = self.take_in(geo_info)
print(res) print(res)
return
except requests.exceptions.ConnectionError: except requests.exceptions.ConnectionError:
# reraise as KubeException, but log stacktrace. # reraise as KubeException, but log stacktrace.
print("打卡失败,请检查github服务器网络状态") print("打卡失败,请检查服务器网络状态")
except Exception as e:
print(e)
print("遇到错误,尝试重试")
print("重试中...",try_count)
try_count+=1
if __name__ == '__main__': if __name__ == '__main__':