【参考】Python Error Note

# Error:Failed to establish a new connection: [Errno 61] Connection refused

Log:HTTPSConnectionPool(host='api.github.com', port=443): Max retries exceeded with url: /search/repositories?q=CVE-2020&sort=updated (Caused by NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x7ff08d7dfd30>: Failed to establish a new connection: [Errno 61] Connection refused',))

Reason:http连接太多没有关闭导致

Plan:

1、增加重试连接次数

import requests
requests.adapters.DEFAULT_RETRIES = 5

2、关闭多余的连接

s = requests.session()
s.keep_alive = False

3、升级requests

pip install --upgrade requests

 4、To overcome this issue (not so much an issue as it is misleading debug trace) you should catch connection related exceptions like so:

try:
    page1 = requests.get(ap)
except requests.exceptions.ConnectionError:
    r.status_code = "Connection refused"

 

Another way to overcome this problem is if you use enough time gap to send requests to server this can be achieved by sleep(timeinsec) function in python (don't forget to import sleep)

posted @ 2020-09-17 14:52  MichaelScofields  阅读(1092)  评论(0编辑  收藏  举报