您现在的位置是:首页 >其他 >访问openAI的API报错:APIConnectionError网站首页其他
访问openAI的API报错:APIConnectionError
APIConnectionError: Error communicating with OpenAI: HTTPSConnectionPool(host='api.openai.com', port=443): Max retries exceeded with url: /v1/completions (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x7fb74df07df0>: Failed to establish a new connection: [Errno 111] Connection refused'))abs
解决方式1:已解决:报错openai.error.APIConnectionError · Issue #5 · GaiZhenbiao/ChuanhuChatGPT · GitHub
如果方式1没用,那可能就是国内被墙掉的原因了。可以尝试解决方式2:
采用国外代理服务器访问openAI,然后再去访问,比如我采用如下方式:
import openai
import os
os.environ["OPENAI_API_KEY"] = "自己的key"
os.environ["OPENAI_API_BASE"] = "国外的服务器"
from langchain.llms import OpenAI
llm = OpenAI(temperature=0.9)
text = "What would be a good company name for a company that makes colorful socks?"
print(llm(text))
然后就可以正常访问了