增加登录重试机制并调整超时时间 #30

This commit is contained in:
NianBroken
2025-01-23 18:00:42 +08:00 Unverified
parent 389e8e109c
commit 1909442c17
2 changed files with 39 additions and 27 deletions
+13 -1
View File
@@ -1,6 +1,7 @@
import os import os
import re import re
import sys import sys
import time
from pprint import pprint from pprint import pprint
from .zfn_api import Client from .zfn_api import Client
@@ -64,7 +65,7 @@ def login(url, username, password):
raspisanie = [] raspisanie = []
ignore_type = [] ignore_type = []
detail_category_type = [] detail_category_type = []
timeout = 5 timeout = 10
student_client = Client( student_client = Client(
cookies=cookies, cookies=cookies,
@@ -75,6 +76,8 @@ def login(url, username, password):
timeout=timeout, timeout=timeout,
) )
attempts = 5 # 最大重试次数
while attempts > 0:
if cookies == {}: if cookies == {}:
lgn = student_client.login(username, password) lgn = student_client.login(username, password)
if lgn["code"] == 1001: if lgn["code"] == 1001:
@@ -104,6 +107,15 @@ def login(url, username, password):
if github_actions: if github_actions:
write_github_summary(run_log, lgn["code"]) write_github_summary(run_log, lgn["code"])
# 如果未成功登录,等待1秒后重试
time.sleep(1)
attempts -= 1 # 剩余重试次数减1
continue
# 如果登录成功,则跳出重试循环
break
if attempts == 0:
sys.exit(0) sys.exit(0)
return student_client return student_client
+1 -1
View File
@@ -38,7 +38,7 @@ class Client:
self.raspisanie = kwargs.get("raspisanie", RASPIANIE) self.raspisanie = kwargs.get("raspisanie", RASPIANIE)
self.ignore_type = kwargs.get("ignore_type", []) self.ignore_type = kwargs.get("ignore_type", [])
self.detail_category_type = kwargs.get("detail_category_type", []) self.detail_category_type = kwargs.get("detail_category_type", [])
self.timeout = kwargs.get("timeout", 3) self.timeout = kwargs.get("timeout", 10)
Client.raspisanie = self.raspisanie Client.raspisanie = self.raspisanie
Client.ignore_type = self.ignore_type Client.ignore_type = self.ignore_type