已解决:报错openai.error.APIConnectionError
Kuzoa opened this issue · 55 comments
返回错误信息:
raise error.APIConnectionError(
openai.error.APIConnectionError: Error communicating with OpenAI: HTTPSConnectionPool(host='api.openai.com', port=443): Max retries exceeded with url: /v1/chat/completions (Caused by SSLError(SSLEOFError(8, 'EOF occurred in violation of protocol (_ssl.c:1131)')))
我试过更换API KEY、使用全局代理都显示这个错误。
Chatgpt说:该代码中使用了Python的raise语句来抛出APIConnectionError异常,这是一个自定义的异常类,表示与OpenAI API通讯时发生了错误。其中的错误信息包括了请求的URL地址以及导致错误的具体原因。从错误信息中可以看出,这个异常是由OpenAI API返回的,表明与该API的通讯过程中出现了SSLError(SSL错误)的异常,而具体的错误原因是违反了SSL协议。因此,这是一个由于与OpenAI API通讯时出现SSL连接问题而导致的异常。
只更改过API KEY没动过其他
被墙了,挂代理
检查一下代理设置
检查一下代理设置
我换了好几个不同节点都不行。但是vscode的chatgpt插件倒是可以正常使用。
所以我觉得问题不是出在代理上
如果有人出现了和我同样的问题,解决方案是卸载urllib3然后重装至1.25.11版本再重新运行一遍就可以。
在终端或命令提示符中卸载urllib3
pip uninstall urllib3
然后,您可以通过使用指定版本号的pip install命令来安装所需的版本:
pip install urllib3==1.25.11
参考自:知乎:解决OpenAI API 挂了代理还是连接不上的问题 openai.error.APIConnectionError
重装了urlib3,又报另外一个错误:
openai.error.RateLimitError: Your access was terminated due to violation of our policies, please check your email for more information. If you believe this is in error and would like to appeal, please contact support@openai.com.
重装了urlib3,又报另外一个错误:
openai.error.RateLimitError: Your access was terminated due to violation of our policies, please check your email for more information. If you believe this is in error and would like to appeal, please contact support@openai.com.
这个链接你参考一下:openAI|如何处理费率限制
重装了urlib3,换了几个不同的代理还是不行呜呜呜
重装了urlib3,换了几个不同的代理还是不行呜呜呜
我朝,我也刚开始试,我换全局代理也不行,不会是要寄了吧
重装了urlib3,换了几个不同的代理还是不行呜呜呜
我又重新安装了一遍,现在可以了,你用https://whoer.net/zh测试一下你现在的ip
呜呜我还是不行
厉害,真的解决了,确实是先卸载urllib3,然后再重新安装,不知道是什么原理,难道是因为证书没有更新的原因吗
我换1.25.11提示要高于1.26.00版本啊 搞死我了
ERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts.
selenium 4.8.3 requires urllib3[socks]~=1.26, but you have urllib3 1.25.11 which is incompatible.
docker 6.0.1 requires urllib3>=1.26.0, but you have urllib3 1.25.11 which is incompatible.
已验证,忽略要求版本1.26.00的提示,直接uninstall 然后安装urllib3 2.25.11即可以正常运行。
Successfully uninstalled urllib3-1.26.15
Successfully installed urllib3-1.25.11
我重装了也不行,我面临的问题是正常使用一直都没问题,但async调用就会一直APIConnectionError
mac下面正常,UB下面出现ssl 问题,启动正常,代理也正常,其他程序访问openai正常, 就是这个有问题,降级了urllib到1.25 也操作过了。
2023-05-08 18:59:54,302 [INFO] [utils.py:407] Your IP region: Australia。
2023-05-08 18:59:54,362 [INFO] [ChuanhuChatbot.py:461]
川虎的温馨提示:访问 http://localhost:7860 查看界面
Reloading javascript...
Running on local URL: http://0.0.0.0:39644
To create a public link, set share=True
in launch()
.
2023-05-08 19:00:21,615 [INFO] [models.py:562] 正在加载OpenAI模型: gpt-3.5-turbo
2023-05-08 19:00:21,615 [INFO] [models.py:604] Model is set to: gpt-3.5-turbo
2023-05-08 19:00:21,880 [INFO] [models.py:562] 正在加载OpenAI模型: gpt-3.5-turbo
2023-05-08 19:00:21,880 [INFO] [models.py:604] Model is set to: gpt-3.5-turbo
2023-05-08 19:00:24,646 [INFO] [base_model.py:283] 输入为:
2023-05-08 19:00:24,655 [INFO] [base_model.py:312]
2023-05-08 19:00:27,560 [ERROR] [models.py:91] 获取API使用情况失败:SOCKSHTTPSConnectionPool(host='api.openai.com', port=443): Max retries exceeded with url: /dashboard/billing/usage?start_date=2023-05-01&end_date=2023-05-31 (Caused by SSLError(SSLEOFError(8, 'EOF occurred in violation of protocol (_ssl.c:1007)')))
mac下面正常,UB下面出现ssl 问题,启动正常,代理也正常,其他程序访问openai正常, 就是这个有问题,降级了urllib到1.25 也操作过了。
2023-05-08 18:59:54,302 [INFO] [utils.py:407] Your IP region: Australia。 2023-05-08 18:59:54,362 [INFO] [ChuanhuChatbot.py:461] 川虎的温馨提示:访问 http://localhost:7860 查看界面 Reloading javascript... Running on local URL: http://0.0.0.0:39644
To create a public link, set
share=True
inlaunch()
. 2023-05-08 19:00:21,615 [INFO] [models.py:562] 正在加载OpenAI模型: gpt-3.5-turbo 2023-05-08 19:00:21,615 [INFO] [models.py:604] Model is set to: gpt-3.5-turbo 2023-05-08 19:00:21,880 [INFO] [models.py:562] 正在加载OpenAI模型: gpt-3.5-turbo 2023-05-08 19:00:21,880 [INFO] [models.py:604] Model is set to: gpt-3.5-turbo 2023-05-08 19:00:24,646 [INFO] [base_model.py:283] 输入为: 2023-05-08 19:00:24,655 [INFO] [base_model.py:312]☹️ Error: Enter the content of the conversation. 2023-05-08 19:00:27,560 [ERROR] [models.py:91] 获取API使用情况失败:SOCKSHTTPSConnectionPool(host='api.openai.com', port=443): Max retries exceeded with url: /dashboard/billing/usage?start_date=2023-05-01&end_date=2023-05-31 (Caused by SSLError(SSLEOFError(8, 'EOF occurred in violation of protocol (_ssl.c:1007)')))
socks代理写错了 原:
// 如果使用代理,请取消注释下面的两行,并替换代理URL "https_proxy": "socks5://127.0.0.1:7890", "http_proxy": "socks5://127.0.0.1:7890",
改成:
// 如果使用代理,请取消注释下面的两行,并替换代理URL "https_proxy": "socks5h://127.0.0.1:7890", "http_proxy": "socks5h://127.0.0.1:7890",
OK了
Successfully uninstalled urllib3-1.26.15 Successfully installed urllib3-1.25.11 我重装了也不行,我面临的问题是正常使用一直都没问题,但async调用就会一直APIConnectionError
你好,我遇到了与你一样的问题,用acreate就不行,请问你解决了吗?
Successfully uninstalled urllib3-1.26.15 Successfully installed urllib3-1.25.11 我重装了也不行,我面临的问题是正常使用一直都没问题,但async调用就会一直APIConnectionError
我也是这个问题,兄弟你解决了吗?
太牛了,解决了,谢谢大佬
docker启动的怎么解决呢
我这边遇到类似情况,代理IP挂掉了,我换成新加坡节点就可以了。
我用的 clash,开启 TUN 模式之后解决问题,上面所有情况都没有解决我的问题。
我用的 clash,开启 TUN 模式之后解决问题,上面所有情况都没有解决我的问题。
我遇到的情况和你一样,开启TUN之后解决了async调用的问题
用的clash开了tun和全局模式,还是报了错误:APIConnectionError: Connection error.
用的clash开了tun和全局模式,还是报了错误:APIConnectionError: Connection error.
请给出详细的错误日志
用的clash开了tun和全局模式,还是报了错误:APIConnectionError: Connection error.
同样,报一样的错误
我pip install urllib3==1.25.11还是解决不了,由于用的clash统一port都是7890,最后在主文件中配置环境解决了问题
import os
os.environ["http_proxy"] = "http://localhost:7890"
os.environ["https_proxy"] = "http://localhost:7890"
请问clash不开全局代理就直接用不了是吗?
我pip install urllib3==1.25.11还是解决不了,由于用的clash统一port都是7890,最后在主文件中配置环境解决了问题 import os
os.environ["http_proxy"] = "http://localhost:7890" os.environ["https_proxy"] = "http://localhost:7890"
已解决
我想跑一下openai给的示例:
import os
from openai import OpenAI
client = OpenAI(
# This is the default and can be omitted
api_key=os.environ.get("OPENAI_API_KEY"),
)
chat_completion = client.chat.completions.create(
messages=[
{
"role": "user",
"content": "Say this is a test",
}
],
model="gpt-3.5-turbo",
)
在colab上面就能跑通,我得vpn是没问题的,为何到pycharm上就报错openai.APIConnectionError: Connection error.
pycharm我用的SSH连接服务器在跑
求哪位大神指点一下?
我想跑一下openai给的示例: import os from openai import OpenAI
client = OpenAI( # This is the default and can be omitted api_key=os.environ.get("OPENAI_API_KEY"), ) chat_completion = client.chat.completions.create( messages=[ { "role": "user", "content": "Say this is a test", } ], model="gpt-3.5-turbo", )
在colab上面就能跑通,我得vpn是没问题的,为何到pycharm上就报错openai.APIConnectionError: Connection error. pycharm我用的SSH连接服务器在跑 求哪位大神指点一下?
在config里设定一下代理的地址吧
我想跑一下openai给的示例: import os from openai import OpenAI
client = OpenAI( # This is the default and can be omitted api_key=os.environ.get("OPENAI_API_KEY"), ) chat_completion = client.chat.completions.create( messages=[ { "role": "user", "content": "Say this is a test", } ], model="gpt-3.5-turbo", )
在colab上面就能跑通,我得vpn是没问题的,为何到pycharm上就报错openai.APIConnectionError: Connection error. pycharm我用的SSH连接服务器在跑 求哪位大神指点一下?
在config里设定一下代理的地址吧
请问怎么设定呢?是通过nano ~/.ssh/config文件里面写入嘛,原谅我刚开始用api,不太熟
我想跑一下openai给的示例: import os from openai import OpenAI
client = OpenAI( # This is the default and can be omitted api_key=os.environ.get("OPENAI_API_KEY"), ) chat_completion = client.chat.completions.create( messages=[ { "role": "user", "content": "Say this is a test", } ], model="gpt-3.5-turbo", )
在colab上面就能跑通,我得vpn是没问题的,为何到pycharm上就报错openai.APIConnectionError: Connection error. pycharm我用的SSH连接服务器在跑 求哪位大神指点一下?
在config里设定一下代理的地址吧
请问怎么设定呢?是通过nano ~/.ssh/config文件里面写入嘛,原谅我刚开始用api,不太熟
在川虎Chat的config.json配置文件里
也有可能是梯子的问题 多换几个节点试试 我就是试了好多办法,最后换了个节点成功了,太离谱了
我的梯子显示终端代理信息为:export https_proxy=http://127.0.0.1:33210 http_proxy=http://127.0.0.1:33210 all_proxy=socks5://127.0.0.1:33211
结果加上
import os
os.environ["http_proxy"] = "http://127.0.0.1:33210"
os.environ["https_proxy"] = "http://127.0.0.1:33210"
就好了
UnsupportedProtocol Traceback (most recent call last)
File ~/.local/lib/python3.10/site-packages/httpx/_transports/default.py:69, in map_httpcore_exceptions()
68 try:
---> 69 yield
70 except Exception as exc:
File ~/.local/lib/python3.10/site-packages/httpx/_transports/default.py:233, in HTTPTransport.handle_request(self, request)
232 with map_httpcore_exceptions():
--> 233 resp = self._pool.handle_request(req)
235 assert isinstance(resp.stream, typing.Iterable)
File ~/.local/lib/python3.10/site-packages/httpcore/_sync/connection_pool.py:167, in ConnectionPool.handle_request(self, request)
166 if scheme == "":
--> 167 raise UnsupportedProtocol(
168 "Request URL is missing an 'http://' or 'https://' protocol."
169 )
170 if scheme not in ("http", "https", "ws", "wss"):
UnsupportedProtocol: Request URL is missing an 'http://' or 'https://' protocol.
The above exception was the direct cause of the following exception:
UnsupportedProtocol Traceback (most recent call last)
File ~/.python/current/lib/python3.10/site-packages/openai/_base_client.py:926, in SyncAPIClient._request(self, cast_to, options, remaining_retries, stream, stream_cls)
...
963 'HTTP Request: %s %s "%i %s"', request.method, request.url, response.status_code, response.reason_phrase
964 )
966 try:
APIConnectionError: Connection error.
求助大神们,这种问题该怎么解决,貌似是协议问题
// First, create the resolveHandler
. This may initially be called with
// "undefined" to ask for all tests in the workspace to be discovered, usually
// when the user opens the Test Explorer for the first time.
controller.resolveHandler = async test => {
if (!test) {
await discoverAllFilesInWorkspace();
} else {
await parseTestsInFileContents(test);
}
};
// When text documents are open, parse tests in them.
vscode.workspace.onDidOpenTextDocument(parseTestsInDocument);
// We could also listen to document changes to re-parse unsaved changes:
vscode.workspace.onDidChangeTextDocument(e => parseTestsInDocument(e.document));
// In this function, we'll get the file TestItem if we've already found it,
// otherwise we'll create it with canResolveChildren = true
to indicate it
// can be passed to the controller.resolveHandler
to gets its children.
function getOrCreateFile(uri: vscode.Uri) {
const existing = controller.items.get(uri.toString());
if (existing) {
return existing;
}
const file = controller.createTestItem(uri.toString(), uri.path.split('/').pop()!, uri);
file.canResolveChildren = true;
return file;
}
function parseTestsInDocument(e: vscode.TextDocument) {
if (e.uri.scheme === 'file' && e.uri.path.endsWith('.md')) {
parseTestsInFileContents(getOrCreateFile(e.uri), e.getText());
}
}
async function parseTestsInFileContents(file: vscode.TestItem, contents?: string) {
// If a document is open, VS Code already knows its contents. If this is being
// called from the resolveHandler when a document isn't open, we'll need to
// read them from disk ourselves.
if (contents === undefined) {
const rawContent = await vscode.workspace.fs.readFile(file.uri);
contents = new TextDecoder().decode(rawContent);
}
// some custom logic to fill in test.children from the contents...
}__
把clash的规则换成全局就解决了
pip install openai==1.6.1
pip install urllib3==1.25.11
试试
如果有人出现了和我同样的问题,解决方案是卸载urllib3然后重装至1.25.11版本再重新运行一遍就可以。
在终端或命令提示符中卸载urllib3 pip uninstall urllib3
然后,您可以通过使用指定版本号的pip install命令来安装所需的版本: pip install urllib3==1.25.11
参考自:知乎:解决OpenAI API 挂了代理还是连接不上的问题 openai.error.APIConnectionError
Yes,good suggestion
我pip install urllib3==1.25.11还是解决不了,由于用的clash统一port都是7890,最后在主文件中配置环境解决了问题 import os
os.environ["http_proxy"] = "http://localhost:7890" os.environ["https_proxy"] = "http://localhost:7890"
同clash,已解决
我在代码中添加了:os.environ["TAVILY_PROXY"] = "http://127.0.0.1:20171" 问题就解决了,本地使用了v2rayA代理,猜测是因为IDE没有配置代理。
我用的 clash,开启 TUN 模式之后解决问题,上面所有情况都没有解决我的问题。
works for me, thx!
代理配置了吗?我是在服务器上用的,完整流程如下,希望有用:)
- 本机:powershell查看ipv4地址
(base) PS C:\Users\xxx> ipconfig
...
IPv4 地址 . . . . . . . . . . . . : 10.47.137.151
...
-
vpn软件看proxy为7890
-
服务器:设置代理。写在.bashrc里然后运行一次
export http_proxy="http://10.47.137.151:7890"
export https_proxy=$http_proxy
export https_proxy=$http_proxy
source .bashrc
-
查看是否设置成功
echo $https_proxy
-
若connection error,打开clash的tun mode