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

APIConnectionError: Error communicating with OpenAI #56

Closed
bramses opened this issue Dec 20, 2021 · 20 comments
Closed

APIConnectionError: Error communicating with OpenAI #56

bramses opened this issue Dec 20, 2021 · 20 comments

Comments

@bramses
Copy link

bramses commented Dec 20, 2021

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
@hallacy
Copy link
Collaborator

hallacy commented Dec 20, 2021

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.

@bramses
Copy link
Author

bramses commented Dec 20, 2021

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
Copy link
Author

bramses commented Dec 21, 2021

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 bramses closed this as completed Dec 21, 2021
@ElementQi
Copy link

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

@dsj96
Copy link

dsj96 commented Mar 3, 2023

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

@ElementQi
Copy link

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

@dsj96
Copy link

dsj96 commented Mar 3, 2023

Thank you! I got it.

@TheKOG
Copy link

TheKOG commented Mar 3, 2023

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

@ElementQi
Copy link

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.

@TheKOG
Copy link

TheKOG commented Mar 3, 2023 via email

@ElementQi
Copy link

写习惯了XD

@lavafool
Copy link

lavafool commented Mar 3, 2023

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

确实解决了,谢谢大佬!

@1337235931
Copy link

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] 由于目标计算机积极拒绝,无法连接。')))

@kfchandsome
Copy link

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

@Cherub1Zhuang
Copy link

关闭vpn就链接超时呀

@Crazy0Dave
Copy link

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和端口

@1337235931
Copy link

1337235931 commented Mar 10, 2023 via email

@kkptm
Copy link

kkptm commented Mar 17, 2023

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

@kkptm
Copy link

kkptm commented Mar 17, 2023

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

@hackersong
Copy link

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

@openai openai locked as off-topic and limited conversation to collaborators Apr 1, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests