Max retries exceeded with url: /error=nh

Python3 : Max retries exceeded with url: /error=nh (Caused by NewConnectionError(’: Failed to establish a new connection: [Errno 61] Connection refused’))
单独测试能连接成功,但是多重连接中始终出现这个错误,网上百度原因是连接次数太多,测试了网上一些办法但是没有效果。
解决办法:
由于程序中有很多连续的网络请求所以用了session,导致连接过多,于是在报错的连接中做了如下的处理:
requests.adapters.DEFAULT_RETRIES = 5 # 增加重连次数
s = requests.session()
s.keep_alive = False # 关闭多余连接
s.get(url) # 你需要的网址

问题解决~

你可能感兴趣的:(Python)