APIconnection error - SSL certificate


I have created an API secret key and trying to run the following documentation:

import openai
import os

from dotenv import load_dotenv, find_dotenv
_ = load_dotenv(find_dotenv())

openai.api_key = os.getenv(‘OPENAI_API_KEY’)

client = openai.OpenAI()

#function to use prompt
def get_completion(prompt, model=“gpt-3.5-turbo”):
messages = [{“role”: “user”, “content”: prompt}]
response = client.chat.completions.create(
return response.choices[0].message.content

text = f"“”
You should express what you want a model to do by \
providing instructions that are as clear and \
specific as you can possibly make them. \
This will guide the model towards the desired output, \
and reduce the chances of receiving irrelevant \
or incorrect responses. Don’t confuse writing a \
clear prompt with writing a short prompt. \
In many cases, longer prompts provide more clarity \
and context for the model, which can lead to \
more detailed and relevant outputs.
prompt = f"“”
Summarize the text delimited by triple backticks \
into a single sentence.
response = get_completion(prompt)

In the section of API keys, it shows it was enabled, and I have set my API key in the environment variables, which works.

But I am getting an error everytime I try to run get_completion(prompt), as such:

ConnectError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1006)

raise APIConnectionError(request=request) from err

APIConnectionError: Connection error.

What do you recommend me to do?


I tried to disable my home/work wifi and connect it to my Iphone instead with hotspot, it was able to run, what do you think would be the issue in this case?