How to solve API connection error and SSL certification error while connecting to GPT-3 open AI?

Viewed 74

I am trying to run a python script(jupyter notebook) by experimenting with GPT-3 open AI to create some NLP project and understand its functions and used cases. I got an error of SSL certification and API connection while I was trying to open a JSON file. I checked some solutions on the internet but it did not offer any remedy. I simply tried connecting to the server through API key but the code was not working. The code I executed is as follows-

import ssl
import certifi
certifi.where()
import openai
api_key='my_api_key'            #it is confidential string
openai.api_key = api_key
response = openai.File.create(file=open("C:\\Users\\pythons_scripts\\Corporate Governance1658287996.json"), purpose="search")
print(response)

So the above script is throwing all of the following errors-

SSLCertVerificationError                  Traceback (most recent call last)    
SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1129)
APIConnectionError                        Traceback (most recent call last)
APIConnectionError: Error communicating with OpenAI

Does anyone know how to get around with this ? or has anyone solved this kind of problem? can someone suggest a solution which will work?

1 Answers

same problem here, trying to use the API from a corporate network. Unfortunately, in similar situations I have had to resort to disabling the SSL verification. I tried adding variations of verify_ssl=False and didn't work, also trying updating conda, certifi etc just in case.

Then I checked various api docs and even the codebase here: https://github.com/openai/openai-python/blob/main/openai/api_requestor.py to see if there was any hint and saw there :

def _make_session() -> requests.Session:
    if not openai.verify_ssl_certs:
        warnings.warn("verify_ssl_certs is ignored; openai always verifies.")

It would look like the developers do not support disabling ssl as a principle. Of course, this is little more than a guess, and I would be delighted to be proven wrong :)

Apologies for not solving your issue Cheers!

Afterthought: you might consider trying another library/method. In https://beta.openai.com/docs/api-reference/introduction they say "You can interact with the API through HTTP requests from any language, via our official Python bindings, our official Node.js library, or a community-maintained library."

Related