SSL: certificate_verify_failed

I tried to open www.api.openai.com by using chrome, but I got " This site can’t be reached". What can I do next?

1 Like

@yuli2.chang What you are trying to achieve?

I am trying to use the API to do text embedding for training a classification model. I obtained a new API code and use this line of code, as suggested by the API website, to test it: response = openai.Completion.create(model=“text-davinci-003”, prompt=“Say this is a test”, temperature=0, max_tokens=7, verify=False). Below is the error message I got:

APIConnectionError: Error communicating with OpenAI: HTTPSConnectionPool(host=‘api.openai.com’, port=443): Max retries exceeded with url: /v1/completions (Caused by SSLError(SSLCertVerificationError(1, ‘[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1129)’)))

I am not able to put the entire trackback here for it is too long. I am using my company’s computer for this project: Windows 10 Enterprise, version 21H2, Processor: 11th Gen Intel(R) Core™ i7-11850H @ 2.50GHz 2.50 GHz. 64-bit operating system, x64-based processor.

@yuli2.chang Please get the certificates from → https://www.api.openai.com/ and add those to your system root or system certificates.

1 Like

The link u shared “http://www.api.openai.com/” is not working. Could you please help me on this?

I’m getting a similar error using python. Nor can I hit the site to get the certs.

raise error.APIConnectionError(
openai.error.APIConnectionError: Error communicating with OpenAI: HTTPSConnectionPool(host=‘api.openai.com’, port=443): Max retries exceeded with url: /v1/engines/text-davinci-002/completions (Caused by SSLError(SSLCertVerificationError(1, ‘[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed certificate in certificate chain (_ssl.c:997)’)))

@vasundhra362000 Please you can also get certs from openai.

@freelanceer.nak Could you please mind sharing the page url from where we can download the certs ? Have tried going to the personal page (where we create the token, but to no avail). Irony of it - asked chatGPT itself the same question, and it asked me to raise a case with support.

Appreciate your response.

@aporelpan are you using a company/work laptop to connect to this API by chance. I experienced the same error and it turned out to be my company’s VPN blocking access to OpenAI API. Disabled the VPN and it worked!

I am also getting the error that SSLCertVerificationFailed.

I had to get the certificates from www.api.openai.com, copy them, and paste them into the Python cacert.pem file. The bad thing is that you have to repeat this every time they update the certificates.

I also encountered such a problem. If I run the. py file in vscode, I will get an error, but if I run the jupyter file in Chrome, it will run very well.

2 Likes

I use nodejs on centos7,nodejs log file: Error with OpenAI API request: Error: certificate has expired,

I update ca root certificate
yum -y install ca-certificates openssl (update version)
update-ca-trust force-enable
update-ca-trust extract
and fixed it.
You can try update ca root certificate

1 Like

Thank you @PaulBellow , this resolved my problem!

search on “Certificates.command” in your Mac finder to locate the file, and you’ll need to run it as root.

1 Like

None of these solutions worked for the API. I still get CERTIFICATE_VERIFY_FAILED error when using Python in a Jupyter notebook. This is on Windows using a VPN. I can get to the OpenAI playground and everything works. I added the certificate from the locations referenced above, but it would be nice if someone would post specific steps that they have used to resolve this issue. I’ve tried all the suggestions, but nothing works. I have a hard time believing this OpenAI Python library works at all.

1 Like

Has anyone gotten the Python OpenAI API library to work without getting this certificate_verify_failed while also using a VPN?

Openai has got the variable verify_ssl_certs set to True and setting it to False has no effect…Wow.

Line 42 openai-python/init.py at 75c90a71e88e4194ce22c71edeb3d2dee7f6ac93 · openai/openai-python · GitHub

verify_ssl_certs = True # No effect. Certificates are always verified.

Anyone have any luck with the ssl fail error, I’ve been stuck on it for days.

Is there any other place I can get the cert from? The open AI site is just not cutting the mustard.

I was able to resolve this issue at my end by following below steps:

  1. Visit https://api.openai.com/v1/engines from the browser and cancel the password prompt

  2. Click on the lock icon on near the browser url to get the certificate info

  3. Depending on your browser find the certificate details and download the root certificate file. For chrome click on connection is secure → Certificate is valid → Details tab and select the top most certificate and click export.

  4. Once downloaded move it to the folder where you need it stored

  5. Add the below code in your main app code to set the environment variable pointing to this certificate we downloaded

import os

os.environ['REQUESTS_CA_BUNDLE'] = '/path/to/certificate.crt'

OR

you can create a .env file in the local folder of your app with below line in it
REQUESTS_CA_BUNDLE = ‘/path/to/certificate.crt’

and load the environment variables in your code file using below code

from dotenv import load_dotenv

load_dotenv()
  1. Once environmental variable is set, openai library in python will use this certificate file for validation automatically and will resolve the issue.

I hope steps would help to resolve the issue for anyone facing it.

20 Likes

Hi - I am still facing issue with this approach. Am i missing anything here?

import os
import openai

os.environ[‘REQUESTS_CA_BUNDLE’] = ‘path to crt file’
openai.api_key = ‘key’

response = openai.Completion.create(
model=“text-davinci-003”,
prompt=“Summarize this for a second-grade student:\n\nJupiter is the fifth planet from the Sun and the largest in the Solar System. It is a gas giant with a mass one-thousandth that of the Sun, but two-and-a-half times that of all the other planets in the Solar System combined. Jupiter is one of the brightest objects visible to the naked eye in the night sky, and has been known to ancient civilizations since before recorded history. It is named after the Roman god Jupiter.[19] When viewed from Earth, Jupiter can be bright enough for its reflected light to cast visible shadows,[20] and is on average the third-brightest natural object in the night sky after the Moon and Venus.”,
temperature=0.7,
max_tokens=256,
top_p=1,
frequency_penalty=0,
presence_penalty=0
)