添加获取图片的超时和重试,防止一直获取而导致程序卡住

This commit is contained in:
2024-07-20 14:54:59 +08:00
parent 2e7e238c77
commit a71e64c24f
2 changed files with 13 additions and 5 deletions

View File

@@ -15,7 +15,7 @@ def get_private_url(key, bucket=BUCKET):
_, resp = UFILE_HANDLER.head_file(bucket, key)
if resp.status_code == -1:
logging.warning(f"uCloud连接失败!即将重试...")
sleep(1)
sleep(3)
continue
if resp.status_code != 200:
logging.warning(f"uCloud中未找到({key})! status: {resp.status_code} error: {resp.error}")
@@ -35,7 +35,7 @@ def copy_file(source_bucket, source_key, target_bucket, target_key):
ret, resp = UFILE_HANDLER.copy(target_bucket, target_key, source_bucket, source_key)
if resp.status_code == -1:
logging.warning(f"uCloud连接失败!即将重试...")
sleep(1)
sleep(3)
continue
if resp.status_code != 200:
logging.warning(
@@ -50,7 +50,7 @@ def upload_file(key, file_path, bucket=BUCKET):
ret, resp = UFILE_HANDLER.putfile(bucket, key, file_path, header=None)
if resp.status_code == -1:
logging.warning(f"uCloud连接失败!即将重试...")
sleep(1)
sleep(3)
continue
if resp.status_code != 200:
logging.warning(f"上传({key})失败! status: {resp.status_code} error: {resp.error}")