def save_img2(imgurl, imgpath, headers='', params=''):
'??????????????????????'
max_try_times = 10 # ??????
sleep_time = 0 # ??????
print('[%s][INFO] Start trying to download ...' % time.asctime()[11:19])
for times in range(1,max_try_times+1):
# print('[%s][INFO] The %s time try begin ...' % (time.asctime()[11:19], times))
try:
# __save_img2(imgurl, dirpath, imgname, headers, params)
response = get_response(imgurl, headers=headers,params=params, stream=False, mtt=10, wt=15, st=2)
img = Image.open(StringIO(response.content))
img.save(imgpath)
img.close()
# print('[%s][INFO] The %s time try success!' % (time.asctime()[11:19], times))
return True
except:
traceback.print_exc()
if times < max_try_times:
print('[%s][WARN][IMG] The %s time try failed!' % (time.asctime()[11:19], times))
time.sleep(sleep_time)
continue
else:
print('[%s][ERROR] The last try failed at last , pass ...' % time.asctime()[11:19])
break
return False
weibo-photo-downloader.py 文件源码
python
阅读 44
收藏 0
点赞 0
评论 0
评论列表
文章目录