weibo-photo-downloader.py 文件源码

python
阅读 36 收藏 0 点赞 0 评论 0

项目:weibo-photo-downloader 作者: Pingze-github 项目源码 文件源码
def retrieve(imgurl,imgpath):
    '??????????????????????'
    max_try_times = 5 # ??????
    wait_time = 15 # ????????
    sleep_time = 3 # ??????
    import socket
    socket.setdefaulttimeout(wait_time)
    #print('[%s][INFO] Start trying to connect ...' % 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:
            urllib.urlretrieve(imgurl,imgpath)
            # print('[%s][INFO] The %s time try success!' % (time.asctime()[11:19], times))
            return True
        except:
            if times < max_try_times:
                # print('[%s][WARN] 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
    # print('[%s][INFO] Successfully get the response!' % time.asctime()[11:19])
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号