增加登录重试机制并调整超时时间 #30
This commit is contained in:
+13
-1
@@ -1,6 +1,7 @@
|
||||
import os
|
||||
import re
|
||||
import sys
|
||||
import time
|
||||
from pprint import pprint
|
||||
from .zfn_api import Client
|
||||
|
||||
@@ -64,7 +65,7 @@ def login(url, username, password):
|
||||
raspisanie = []
|
||||
ignore_type = []
|
||||
detail_category_type = []
|
||||
timeout = 5
|
||||
timeout = 10
|
||||
|
||||
student_client = Client(
|
||||
cookies=cookies,
|
||||
@@ -75,6 +76,8 @@ def login(url, username, password):
|
||||
timeout=timeout,
|
||||
)
|
||||
|
||||
attempts = 5 # 最大重试次数
|
||||
while attempts > 0:
|
||||
if cookies == {}:
|
||||
lgn = student_client.login(username, password)
|
||||
if lgn["code"] == 1001:
|
||||
@@ -104,6 +107,15 @@ def login(url, username, password):
|
||||
if github_actions:
|
||||
write_github_summary(run_log, lgn["code"])
|
||||
|
||||
# 如果未成功登录,等待1秒后重试
|
||||
time.sleep(1)
|
||||
attempts -= 1 # 剩余重试次数减1
|
||||
continue
|
||||
|
||||
# 如果登录成功,则跳出重试循环
|
||||
break
|
||||
|
||||
if attempts == 0:
|
||||
sys.exit(0)
|
||||
|
||||
return student_client
|
||||
|
||||
+1
-1
@@ -38,7 +38,7 @@ class Client:
|
||||
self.raspisanie = kwargs.get("raspisanie", RASPIANIE)
|
||||
self.ignore_type = kwargs.get("ignore_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.ignore_type = self.ignore_type
|
||||
|
||||
|
||||
Reference in New Issue
Block a user