mirror of
https://github.com/YuCat-OVO/BaiduNetdisk-Docker
synced 2025-05-10 20:10:04 +08:00
retry
This commit is contained in:
parent
09a4a3a8bc
commit
becdb84569
@ -16,7 +16,7 @@ GLOBAL_VERSION = [
|
|||||||
]
|
]
|
||||||
|
|
||||||
# 定义需要检测的版本号范围
|
# 定义需要检测的版本号范围
|
||||||
max_version = [4, 20, 0]
|
max_version = [4, 18, 0]
|
||||||
min_version = [4, 17, 0]
|
min_version = [4, 17, 0]
|
||||||
|
|
||||||
# 定义请求延时时间(秒)
|
# 定义请求延时时间(秒)
|
||||||
@ -153,15 +153,28 @@ def check_version(version):
|
|||||||
"""检测指定版本号是否可用"""
|
"""检测指定版本号是否可用"""
|
||||||
url = make_url_temple().format(".".join(str(v) for v in version))
|
url = make_url_temple().format(".".join(str(v) for v in version))
|
||||||
# url = "https://httpbin.org/status/200"
|
# url = "https://httpbin.org/status/200"
|
||||||
print("Getting {0}".format(url))
|
# print("Getting {0}".format(url))
|
||||||
response = requests.head(
|
|
||||||
url,
|
max_attempts = 5
|
||||||
headers=GLOBAL_HEADER,
|
attempt = 0
|
||||||
)
|
|
||||||
if response.status_code == 200:
|
while attempt < max_attempts:
|
||||||
return True
|
try:
|
||||||
else:
|
response = requests.head(
|
||||||
return False
|
url,
|
||||||
|
headers=GLOBAL_HEADER,
|
||||||
|
)
|
||||||
|
if response.status_code == 200:
|
||||||
|
return True
|
||||||
|
else:
|
||||||
|
return False
|
||||||
|
except Exception as e:
|
||||||
|
print(f"An error occurred: {e}")
|
||||||
|
attempt += 1
|
||||||
|
time.sleep(1) # 等待1秒再重试
|
||||||
|
|
||||||
|
if attempt == max_attempts:
|
||||||
|
print("Failed after several attempts")
|
||||||
|
|
||||||
|
|
||||||
def find_latest_version(min_version, max_version):
|
def find_latest_version(min_version, max_version):
|
||||||
@ -185,9 +198,9 @@ def find_latest_version(min_version, max_version):
|
|||||||
)
|
)
|
||||||
return version
|
return version
|
||||||
else:
|
else:
|
||||||
print(
|
# print(
|
||||||
"version {0} is not available".format(".".join(str(v) for v in version))
|
# "version {0} is not available".format(".".join(str(v) for v in version))
|
||||||
)
|
# )
|
||||||
time.sleep(GLOBAL_REQUEST_DELAY)
|
time.sleep(GLOBAL_REQUEST_DELAY)
|
||||||
|
|
||||||
# 找不到可用版本号,返回None
|
# 找不到可用版本号,返回None
|
||||||
@ -199,4 +212,3 @@ if __name__ == "__main__":
|
|||||||
find_latest_version(min_version, max_version)
|
find_latest_version(min_version, max_version)
|
||||||
urls = parse_url_from_json()
|
urls = parse_url_from_json()
|
||||||
make_info_json(urls)
|
make_info_json(urls)
|
||||||
pass
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user