SSL: certificate_verify_failed

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.

21 Likes