openai-python icon indicating copy to clipboard operation
openai-python copied to clipboard

APIConnectionError: Error communicating with OpenAI

Open bramses opened this issue 4 years ago • 20 comments

Running into certificate errors when trying to ping the API. Happens both in virtualenv and regular Python

Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/openai/api_requestor.py", line 255, in request_raw
    result = _thread_context.session.request(
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/requests/sessions.py", line 542, in request
    resp = self.send(prep, **send_kwargs)
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/requests/sessions.py", line 655, in send
    r = adapter.send(request, **kwargs)
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/requests/adapters.py", line 514, in send
    raise SSLError(e, request=request)
requests.exceptions.SSLError: HTTPSConnectionPool(host='api.openai.com', port=443): Max retries exceeded with url: /v1/engines (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed certificate in certificate chain (_ssl.c:1131)')))

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "search.py", line 21, in <module>
    main()
  File "search.py", line 9, in main
    engines = openai.Engine.list()
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/openai/api_resources/abstract/listable_api_resource.py", line 27, in list
    response, _, api_key = requestor.request(
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/openai/api_requestor.py", line 98, in request
    result = self.request_raw(
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/openai/api_requestor.py", line 265, in request_raw
    raise error.APIConnectionError("Error communicating with OpenAI") from e
openai.error.APIConnectionError: Error communicating with OpenAI

bramses avatar Dec 20 '21 01:12 bramses

Hello! Thank you for reaching out!

The CERTIFICATE_VERIFY_FAILED error might be caused by an outdated certifi package in Python. Here's a relevant discussion: https://stackoverflow.com/questions/51925384/unable-to-get-local-issuer-certificate-when-using-requests-in-python. Let me know if this doesn't help, and we'll keep troubleshooting.

hallacy avatar Dec 20 '21 03:12 hallacy

Unfortunately the --upgrade flag seems to have been ineffective :(

(.venv) python % pip install --upgrade certifi
Requirement already satisfied: certifi in ./.venv/lib/python3.8/site-packages (2021.10.8)

I also ran the verification func from certifi lib and got the expected path:

(.venv) python % python -m certifi            
~/code/.venv/lib/python3.8/site-packages/certifi/cacert.pem

bramses avatar Dec 20 '21 03:12 bramses

I figured it out, my VPN was blocking external requests, for anyone who has a M1 Macbook in the future make sure your network calls aren't being tunneled by another app :)

bramses avatar Dec 21 '21 01:12 bramses

I figured it out, my VPN was blocking external requests, for anyone who has a M1 Macbook in the future make sure your network calls aren't being tunneled by another app :)

Same as win10. I figured out that just now by simply shutting down my clash terminal XD

ElementQi avatar Feb 07 '23 07:02 ElementQi

HI [ElementQi] I have the same problem, Can you tell me how to shut down the clash terminal XD? Thanks.

dsj96 avatar Mar 03 '23 08:03 dsj96

HI [ElementQi] I have the same problem, Can you tell me how to shut down the clash terminal XD? Thanks.

You may misunderstand what am I talking about. XD is an emoji. You just need to shutdown your VPN services on your device. 哥,XD就是个表情,你把你电脑上的VPN全关了就行,开VPN有时候访问不了chatGPT

ElementQi avatar Mar 03 '23 08:03 ElementQi

Thank you! I got it.

dsj96 avatar Mar 03 '23 08:03 dsj96

All methods above can not solve my problem , because I'm in China , where one can't connect to openai without VPN or Proxy. For my Chinese compatriots following method works: https://www.zhihu.com/question/587322263/answer/2919916984

TheKOG avatar Mar 03 '23 10:03 TheKOG

All methods above can not solve my problem , because I'm in China , where one can't connect to openai without VPN or Proxy. For my Chinese compatriots following method works: https://www.zhihu.com/question/587322263/answer/2919916984

I'm in China as well. One of my accounts is using a google account by implementing an Indian virtual phone number, and it works only when I don't use any proxies(As for website login, I need to use VPN to login google account and then close it to use the chatGPT interface). One of my friends' accounts is signed up with his qqmail and Indian phone number, which can only access openAI by using VPN. That's weird.

ElementQi avatar Mar 03 '23 10:03 ElementQi

都是中国人拽啥洋文XD

------------------ 原始邮件 ------------------ 发件人: @.>; 发送时间: 2023年3月3日(星期五) 晚上6:27 收件人: @.>; 抄送: @.>; @.>; 主题: Re: [openai/openai-python] APIConnectionError: Error communicating with OpenAI (Issue #56)

All methods above can not solve my problem , because I'm in China , where one can't connect to openai without VPN or Proxy. For my Chinese compatriots following method works: https://www.zhihu.com/question/587322263/answer/2919916984

I'm in China as well. One of my accounts is using a google account by implementing an Indian virtual phone number, and it works only when I don't use any proxies(As for website login, I need to use VPN to login google account and then close it to use the chatGPT interface). One of my friends' accounts is signed up with his qqmail and Indian phone number, which can only access openAI by using VPN. That's weird.

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you commented.Message ID: @.***>

TheKOG avatar Mar 03 '23 10:03 TheKOG

写习惯了XD

ElementQi avatar Mar 03 '23 10:03 ElementQi

All methods above can not solve my problem , because I'm in China , where one can't connect to openai without VPN or Proxy. For my Chinese compatriots following method works: https://www.zhihu.com/question/587322263/answer/2919916984

确实解决了,谢谢大佬!

lavafool avatar Mar 03 '23 14:03 lavafool

All methods above can not solve my problem , because I'm in China , where one can't connect to openai without VPN or Proxy. For my Chinese compatriots following method works: https://www.zhihu.com/question/587322263/answer/2919916984

您好,加上后又报另一个错误。这个有办法解决吗? openai.error.APIConnectionError: Error communicating with OpenAI: HTTPSConnectionPool(host='api.openai.com', port=443): Max retries exceeded with url: /v1/chat/completions (Caused by ProxyError('Cannot connect to proxy.', NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x000001A5B8C1CB88>: Failed to establish a new connection: [WinError 10061] 由于目标计算机积极拒绝,无法连接。')))

zjr10101 avatar Mar 03 '23 14:03 zjr10101

我也遇到这个问题,怎么解决,关闭VPN连接不上

kfchandsome avatar Mar 04 '23 11:03 kfchandsome

关闭vpn就链接超时呀

Cherub1Zhuang avatar Mar 07 '23 09:03 Cherub1Zhuang

All methods above can not solve my problem , because I'm in China , where one can't connect to openai without VPN or Proxy. For my Chinese compatriots following method works: https://www.zhihu.com/question/587322263/answer/2919916984

您好,加上后又报另一个错误。这个有办法解决吗? openai.error.APIConnectionError: Error communicating with OpenAI: HTTPSConnectionPool(host='api.openai.com', port=443): Max retries exceeded with url: /v1/chat/completions (Caused by ProxyError('Cannot connect to proxy.', NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x000001A5B8C1CB88>: Failed to establish a new connection: [WinError 10061] 由于目标计算机积极拒绝,无法连接。')))

确定代理ip和代理端口写的是自己挂的vpn的ip和端口

Crazy0Dave avatar Mar 10 '23 11:03 Crazy0Dave

我已经把api接口调通了,解决了问题,但是,被封了,不知道因为什么,在网上有很多类似的。但是chatgpt还可以用,api禁止访问了。

------------------ 原始邮件 ------------------ 发件人: "openai/openai-python" @.>; 发送时间: 2023年3月10日(星期五) 晚上7:26 @.>; @.@.>; 主题: Re: [openai/openai-python] APIConnectionError: Error communicating with OpenAI (Issue #56)

All methods above can not solve my problem , because I'm in China , where one can't connect to openai without VPN or Proxy. For my Chinese compatriots following method works: https://www.zhihu.com/question/587322263/answer/2919916984

您好,加上后又报另一个错误。这个有办法解决吗? openai.error.APIConnectionError: Error communicating with OpenAI: HTTPSConnectionPool(host='api.openai.com', port=443): Max retries exceeded with url: /v1/chat/completions (Caused by ProxyError('Cannot connect to proxy.', NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x000001A5B8C1CB88>: Failed to establish a new connection: [WinError 10061] 由于目标计算机积极拒绝,无法连接。')))

确定代理ip和代理端口写的是自己挂的vpn的ip和端口

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you commented.Message ID: @.***>

zjr10101 avatar Mar 10 '23 11:03 zjr10101

我租用了一个美国服务器准备部署一个跳板,结果在服务器上就无法ping通api.openai.com

kkptm avatar Mar 17 '23 22:03 kkptm

在国内又搞了台服务器,在服务器上挂VPN又可以==!

kkptm avatar Mar 17 '23 22:03 kkptm

import openai openai.organization="XXXX" openai.api_key = "XXXX" proxies = { 'http': "http://xxxx:xxxx", 'https': "http://xxxx:xxxx"} openai.proxy = proxies openai.Model.list()

hackersong avatar Apr 01 '23 09:04 hackersong