原因:访问URL超过最大连接数,关闭长连接可解决,代码如下
import requests
# 原代码
response = requests.post(url, data=data)
# 修复后代码
# 方案一:设置headers关闭持久链接
headers = {
'Connection': 'close'
}
response = requests.post(url, data=data, headers=headers)
#方案二:设置Keep-alive = False
s = requests.session()
s.keep_alive = False
s.post(url, data=data)
原因:域名无法访问,经检查CentOS未配置DNS,Linux查看DNS配置命令cat /etc/resolv.conf
HTTPConnectionPool(host='url', port=port): Max retries exceeded with url: /path (Caused by NewConnectionError(': Failed to establish a new connection: [Errno -2] Name or service not known',))