HTTPSConnectionPool(host=‘kaipu3.openai.azure.com’, port=443): Max retries exceeded with url: /openai/deployments/gpt4/chat/completions?api-version=2023-07-01-preview (Caused by NewConnectionError(‘<urllib3.connection.HTTPSConnection object at 0x7f24aefa13a0>: Failed to establish a new connection: [Errno -3] Temporary failure in name resolution’))
报错原因1
开了代理
解决方式1
unset https_proxy
unset http_proxy
报错原因2
连接池问题
解决方式2
import urllib3
import requests
#增加池子的大小
http = urllib3.PoolManager(num_pools=50)
s = requests.Session()
# 增加重试连接次数
s.mount('http://', HTTPAdapter(max_retries=5))
s.mount('https://', HTTPAdapter(max_retries=5))
# 关闭多余连接
s.keep_alive = False
# 取消验证证书
s.verify = False
# 关闭在设置了verify=False后的错误提示
urllib3.disable_warnings()
# 发起请求
res = s.get(url=url, headers=headers, timeout=30)
# 关闭多余连接
s.close()