openai

您所在的位置:网站首页 js调用c程序 openai

openai

2023-03-09 04:14| 来源: 网络整理| 查看: 265

因为目前openai对地区限制的原因,即使设置了全局代理使用API调用时,还是会出现科学上网代理的错误问题。

openai库 == 0.26.5

【错误提示】:

raise error.APIConnectionError(

openai.error.APIConnectionError: Error communicating with OpenAI: HTTPSConnectionPool(host='api.openai.com', port=443): Max retries exceeded with url: /v1/models (Caused by SSLError(SSLEOFError(8, 'EOF occurred in violation of protocol (_ssl.c:1123)')))

【解决方法】:

①打开文件路径:.ENV\GPTdemo-uQtPOhRR\lib\site-packages\openai\api_requestor.py(openai库路径)

②找到“if not hasattr(_thread_context, "session"):”方法,并在此方法上方加入代理

# proxy = { #    'http': 'http://:', #    'https': 'https://:' #       } proxy={ 'http':'127.0.0.1:10809', 'https':'127.0.0.1:10809' }

③在“result = _thread_context.session.request(”中加入代理

result = _thread_context.session.request( method, abs_url, headers=headers, data=data, files=files, stream=stream, timeout=request_timeout if request_timeout else TIMEOUT_SECS, proxies=proxy    # 新增此行 )

再次运行API测试代码发现以及成功返回数据。



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3