文章内容

2019/4/26 9:16:01,作 者: 黄兵

Max retries exceeded with url

今天早上查看服务器上面有一个服务,出现了如下错误:

requests.exceptions.ConnectionError: HTTPSConnectionPool(host='www.pdflibr.com', port=443): Max retries exceeded with url: /xxx (Caused by NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x7fde012da9b0>: Failed to establish a new connection: [Errno 110] Connection timed out',))


出现问题的原因:

连接超时,导致重试次数过多。


解决方案:

加上timeout设置,具体如下:

request_content = requests.post('https://www.pdflibr.com/xxx', data=payload,
                                                                headers=headers, timeout=5)

其中timeout=5是设置超时5s,如果超过5s,异常判断:

except TimeoutError:
    # 如果超时,间隔1s继续
    time.sleep(1)
    continue


参考资料:

1、timeout


黄兵个人博客原创。

转载请注明出处:黄兵个人博客 - Max retries exceeded with url

分享到:

发表评论

评论列表