执行python程序时,需要挂梯子调用openai api,遇到下面的错误:
User openai.error.APIConnectionError: Error communicating with OpenAI: HTTPSConnectionPool(host='api.openai.com', port=443): Max retries exceeded with url: /v1/embeddings (Caused by ProxyError('Unable to connect to proxy', SSLError(SSLZeroReturnError(6, 'TLS/SSL connection has been closed (EOF) (_ssl.c:1135)'))))
在代码中加入下面这行设置代理就可以解决了:
proxy = {
'http': 'http://localhost:7890',
'https': 'http://localhost:7890'
}
openai.proxy = proxy