Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

已解决:报错openai.error.APIConnectionError #5

Closed
Kuzoa opened this issue Mar 3, 2023 · 55 comments
Closed

已解决:报错openai.error.APIConnectionError #5

Kuzoa opened this issue Mar 3, 2023 · 55 comments

Comments

@Kuzoa
Copy link

Kuzoa commented Mar 3, 2023

返回错误信息:
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连接问题而导致的异常。

@Kuzoa
Copy link
Author

Kuzoa commented Mar 3, 2023

只更改过API KEY没动过其他

@travellerse
Copy link

被墙了,挂代理

@travellerse
Copy link

检查一下代理设置

@Kuzoa
Copy link
Author

Kuzoa commented Mar 3, 2023

检查一下代理设置

我换了好几个不同节点都不行。但是vscode的chatgpt插件倒是可以正常使用。
所以我觉得问题不是出在代理上

@Kuzoa Kuzoa closed this as completed Mar 3, 2023
@Kuzoa
Copy link
Author

Kuzoa commented Mar 3, 2023

如果有人出现了和我同样的问题,解决方案是卸载urllib3然后重装至1.25.11版本再重新运行一遍就可以。

在终端或命令提示符中卸载urllib3
pip uninstall urllib3

然后,您可以通过使用指定版本号的pip install命令来安装所需的版本:
pip install urllib3==1.25.11

参考自:知乎:解决OpenAI API 挂了代理还是连接不上的问题 openai.error.APIConnectionError

@Kuzoa Kuzoa reopened this Mar 3, 2023
@Kuzoa Kuzoa changed the title 报错 已解决:报错openai.error.APIConnectionError Mar 3, 2023
@dsjzazs
Copy link

dsjzazs commented Mar 4, 2023

重装了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 [email protected].

@Kuzoa
Copy link
Author

Kuzoa commented Mar 4, 2023

重装了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 [email protected].

这个链接你参考一下:openAI|如何处理费率限制

@Conghui-Niu
Copy link

重装了urlib3,换了几个不同的代理还是不行呜呜呜

@lianli2352
Copy link

重装了urlib3,换了几个不同的代理还是不行呜呜呜

我朝,我也刚开始试,我换全局代理也不行,不会是要寄了吧

@lianli2352
Copy link

重装了urlib3,换了几个不同的代理还是不行呜呜呜

我又重新安装了一遍,现在可以了,你用https://whoer.net/zh测试一下你现在的ip

@Gmorning730
Copy link

呜呜我还是不行

@Gmorning730
Copy link

image
更新了版本还是这个问题

@SongTe1116
Copy link

image更新了版本还是这个问题

请问您成功解决了吗

@zhangqicheng
Copy link

厉害,真的解决了,确实是先卸载urllib3,然后再重新安装,不知道是什么原理,难道是因为证书没有更新的原因吗

@ltbyxt
Copy link

ltbyxt commented Apr 18, 2023

我换1.25.11提示要高于1.26.00版本啊 搞死我了

@ltbyxt
Copy link

ltbyxt commented Apr 18, 2023

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.

@tammypi
Copy link

tammypi commented Apr 20, 2023

已验证,忽略要求版本1.26.00的提示,直接uninstall 然后安装urllib3 2.25.11即可以正常运行。

@GaiZhenbiao GaiZhenbiao pinned this issue Apr 20, 2023
@jinghan23
Copy link

Successfully uninstalled urllib3-1.26.15
Successfully installed urllib3-1.25.11
我重装了也不行,我面临的问题是正常使用一直都没问题,但async调用就会一直APIConnectionError

@guoqingkong
Copy link

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] ☹️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)')))

@guoqingkong
Copy link

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] ☹️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了

@WANGBohaO-jpg
Copy link

Successfully uninstalled urllib3-1.26.15 Successfully installed urllib3-1.25.11 我重装了也不行,我面临的问题是正常使用一直都没问题,但async调用就会一直APIConnectionError

你好,我遇到了与你一样的问题,用acreate就不行,请问你解决了吗?

@ArsenalCheng
Copy link

Successfully uninstalled urllib3-1.26.15 Successfully installed urllib3-1.25.11 我重装了也不行,我面临的问题是正常使用一直都没问题,但async调用就会一直APIConnectionError

我也是这个问题,兄弟你解决了吗?

@yhyu13
Copy link

yhyu13 commented Jun 14, 2023

@ALL 香港某些vpn服务器ip被openai封了,用日本的

@Hongru0306
Copy link

太牛了,解决了,谢谢大佬

@Undertone0809
Copy link

我用的 clash,开启 TUN 模式之后解决问题,上面所有情况都没有解决我的问题。

@c2j
Copy link

c2j commented Nov 5, 2023

我用的 clash,开启 TUN 模式之后解决问题,上面所有情况都没有解决我的问题。

我遇到的情况和你一样,开启TUN之后解决了async调用的问题

@Ybszzzziz
Copy link

用的clash开了tun和全局模式,还是报了错误:APIConnectionError: Connection error.

@GaiZhenbiao
Copy link
Owner

用的clash开了tun和全局模式,还是报了错误:APIConnectionError: Connection error.

请给出详细的错误日志

@zhuzhu-lu
Copy link

用的clash开了tun和全局模式,还是报了错误:APIConnectionError: Connection error.

同样,报一样的错误

@stephencurry300728
Copy link

我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"

@Liumankit
Copy link

请问clash不开全局代理就直接用不了是吗?

@Black2716
Copy link

我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"

已解决

@JiangyueAnn
Copy link

我想跑一下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连接服务器在跑
求哪位大神指点一下?

@GaiZhenbiao
Copy link
Owner

我想跑一下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里设定一下代理的地址吧

@JiangyueAnn
Copy link

我想跑一下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,不太熟

@GaiZhenbiao
Copy link
Owner

我想跑一下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配置文件里

@CnadyWF002
Copy link

也有可能是梯子的问题 多换几个节点试试 我就是试了好多办法,最后换了个节点成功了,太离谱了

@Amber-nannan
Copy link

我的梯子显示终端代理信息为: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"
就好了

@wyj19322
Copy link

wyj19322 commented Apr 1, 2024


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.

求助大神们,这种问题该怎么解决,貌似是协议问题

@jiahui010406
Copy link

Screenshot 2024-04-01 at 5 11 57 PM proxies已经在代码特别注明了,规则我也写了, 在curl连接和各种vpn检查都做了,vpn是没问题的,但只要一调用api,就会出现connection error,还有什么办法吗? Screenshot 2024-04-01 at 5 11 01 PM

@jiahui010406
Copy link

Screenshot 2024-04-01 at 5 11 57 PM proxies已经在代码特别注明了,规则我也写了, 在curl连接和各种vpn检查都做了,vpn是没问题的,但只要一调用api,就会出现connection error,还有什么办法吗? Screenshot 2024-04-01 at 5 11 01 PM

这个是我遇到的error
Screenshot 2024-04-01 at 5 14 01 PM
Screenshot 2024-04-01 at 5 15 11 PM

@ANS12S
Copy link

ANS12S commented May 14, 2024

Screenshot 2024-04-01 at 5 11 57 PM proxies已经在代码特别注明了,规则我也写了, 在curl连接和各种vpn检查都做了,vpn是没问题的,但只要一调用api,就会出现connection error,还有什么办法吗? Screenshot 2024-04-01 at 5 11 01 PM

这个是我遇到的error Screenshot 2024-04-01 at 5 14 01 PM Screenshot 2024-04-01 at 5 15 11 PM

请问你解决这个问题了吗,我也出现了同样的问题

@wyj19322
Copy link

wyj19322 commented May 15, 2024 via email

@hossain666
Copy link

// 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...
}__

@zhourui8
Copy link

把clash的规则换成全局就解决了

@Serendipity-hope
Copy link

pip install openai==1.6.1
pip install urllib3==1.25.11
试试

@MuHeDing
Copy link

MuHeDing commented Aug 9, 2024

如果有人出现了和我同样的问题,解决方案是卸载urllib3然后重装至1.25.11版本再重新运行一遍就可以。

在终端或命令提示符中卸载urllib3 pip uninstall urllib3

然后,您可以通过使用指定版本号的pip install命令来安装所需的版本: pip install urllib3==1.25.11

参考自:知乎:解决OpenAI API 挂了代理还是连接不上的问题 openai.error.APIConnectionError

Yes,good suggestion

@philiporz
Copy link

我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,已解决

@amya-eng
Copy link

我在代码中添加了:os.environ["TAVILY_PROXY"] = "http://127.0.0.1:20171" 问题就解决了,本地使用了v2rayA代理,猜测是因为IDE没有配置代理。

@dengmengjie
Copy link

我用的 clash,开启 TUN 模式之后解决问题,上面所有情况都没有解决我的问题。

works for me, thx!

@lemon1-ui
Copy link

我也用的clash 开启TUN模式 global代理 还是不行请问该如何解决呢
image

@dengmengjie
Copy link

dengmengjie commented Oct 24, 2024

我也用的clash 开启TUN模式 global代理 还是不行请问该如何解决呢 image

代理配置了吗?我是在服务器上用的,完整流程如下,希望有用:)

  1. 本机:powershell查看ipv4地址
(base) PS C:\Users\xxx> ipconfig
...
   IPv4 地址 . . . . . . . . . . . . : 10.47.137.151
...
  1. vpn软件看proxy为7890

  2. 服务器:设置代理。写在.bashrc里然后运行一次

export http_proxy="http://10.47.137.151:7890"
export https_proxy=$http_proxy
export https_proxy=$http_proxy
source .bashrc
  1. 查看是否设置成功
    echo $https_proxy

  2. 若connection error,打开clash的tun mode

@lemon1-ui
Copy link

lemon1-ui commented Oct 24, 2024 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests