This commit is contained in:
caiwx86 2023-04-06 01:54:06 +08:00
parent 2555c8a39d
commit a8f44ec334

View File

@ -183,25 +183,23 @@ class downloadUtils:
try:
response = requests.get(
image_url, headers=cls.headers, timeout=timeout, proxies=proxies)
while response.status_code != 200 and repair_count <= 5:
if response.status_code != 200 and repair_count <= 5:
raise NameError("下载异常")
with open(temp_path, 'wb') as f:
f.write(response.content)
time.sleep(0.7)
cls.download_image(image_url,dst_dir,file_name)
print(f'重试:第{repair_count}{image_url}')
cls.down_queue.put([file_name,image_url,dst_dir])
repair_count += 1
with open(temp_path, 'wb') as f:
f.write(response.content)
response.close()
response.close()
#验证是否是图像
if fu.ver_file(temp_path,type="image"):
shutil.move(temp_path, file_path)
print("## OK: {} {}".format(file_path, image_url))
else:
print("## Fail: {} {}".format(image_url, "图像损坏"))
cls.down_queue.put([file_name,image_url,dst_dir])
raise NameError("## Fail: {} {}".format(image_url, "图像损坏"))
except Exception as e:
print(f"common_down() 出错了 {e}")
print(f'重试:第{repair_count}{image_url}')
cls.down_queue.put([file_name,image_url,dst_dir])
repair_count += 1
@classmethod
def download_image(cls,timeout=20, proxy_type=None, proxy=None,type="image"):