SSL: certificate_verify_failed

Hello,

I am trying to connect to the OpenAI api from python, a simple test, but I am not succeeding as I always get the same error:

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

I have tried to force it to ignore the certificate verification but I can’t, and I don’t know how to make it point to a correct certificate either.

Anyone knows how I can solve this?

Thanks in advance.

1 Like

Welcome to the community.

Can you share the code you’re using with us? Are you hitting the API more than once in quick succession?

ETA: This might help, but we don’t know your OS and other details…

3 Likes

Of course. This is a simple example that I copied from one of the tutorials.

import pandas as pd
import openai
import certifi
certifi.where()
import requests

openai.api_key = ‘MY_API_KEY’

response = openai.Completion.create(
model=“text-davinci-003”,
prompt=“I am a highly intelligent question answering bot. If you ask me a question that is rooted in truth, I will give you the answer. If you ask me a question that is nonsense, trickery, or has no clear answer, I will respond with "Unknown".\n\nQ: What is human life expectancy in the United States?\nA: Human life expectancy in the United States is 78 years.\n\nQ: Who was president of the United States in 1955?\nA: Dwight D. Eisenhower was president of the United States in 1955.\n\nQ: Which party did he belong to?\nA: He belonged to the Republican Party.\n\nQ: What is the square root of banana?\nA: Unknown\n\nQ: How does a telescope work?\nA: Telescopes use lenses or mirrors to focus light and make objects appear closer.\n\nQ: Where were the 1992 Olympics held?\nA: The 1992 Olympics were held in Barcelona, Spain.\n\nQ: How many squigs are in a bonk?\nA: Unknown\n\nQ: Where is the Valley of Kings?\nA:”,
temperature=0,
max_tokens=100,
top_p=1,
frequency_penalty=0.0,
presence_penalty=0.0,
stop=[“\n”]
)

Of course. This is a simple example that I copied from one of the tutorials.

import pandas as pd
import openai
import certifi
certifi.where()
import requests

openai.api_key = 'MY_API_KEY'

response = openai.Completion.create(
  model="text-davinci-003",
  prompt="I am a highly intelligent question answering bot. If you ask me a question that is rooted in truth, I will give you the answer. If you ask me a question that is nonsense, trickery, or has no clear answer, I will respond with \"Unknown\".\n\nQ: What is human life expectancy in the United States?\nA: Human life expectancy in the United States is 78 years.\n\nQ: Who was president of the United States in 1955?\nA: Dwight D. Eisenhower was president of the United States in 1955.\n\nQ: Which party did he belong to?\nA: He belonged to the Republican Party.\n\nQ: What is the square root of banana?\nA: Unknown\n\nQ: How does a telescope work?\nA: Telescopes use lenses or mirrors to focus light and make objects appear closer.\n\nQ: Where were the 1992 Olympics held?\nA: The 1992 Olympics were held in Barcelona, Spain.\n\nQ: How many squigs are in a bonk?\nA: Unknown\n\nQ: Where is the Valley of Kings?\nA:",
  temperature=0,
  max_tokens=100,
  top_p=1,
  frequency_penalty=0.0,
  presence_penalty=0.0,
  stop=["\n"]
)

Of course. This is a simple example that I copied from one of the tutorials. I am working on Windows 10.

import pandas as pd
import openai
import certifi
certifi.where()
import requests

openai.api_key = 'MY_API_KEY'

response = openai.Completion.create(
  model="text-davinci-003",
  prompt="I am a highly intelligent question answering bot. If you ask me a question that is rooted in truth, I will give you the answer. If you ask me a question that is nonsense, trickery, or has no clear answer, I will respond with \"Unknown\".\n\nQ: What is human life expectancy in the United States?\nA: Human life expectancy in the United States is 78 years.\n\nQ: Who was president of the United States in 1955?\nA: Dwight D. Eisenhower was president of the United States in 1955.\n\nQ: Which party did he belong to?\nA: He belonged to the Republican Party.\n\nQ: What is the square root of banana?\nA: Unknown\n\nQ: How does a telescope work?\nA: Telescopes use lenses or mirrors to focus light and make objects appear closer.\n\nQ: Where were the 1992 Olympics held?\nA: The 1992 Olympics were held in Barcelona, Spain.\n\nQ: How many squigs are in a bonk?\nA: Unknown\n\nQ: Where is the Valley of Kings?\nA:",
  temperature=0,
  max_tokens=100,
  top_p=1,
  frequency_penalty=0.0,
  presence_penalty=0.0,
  stop=["\n"]
)

Hrm. All packages up to date?

Can you hit the API from the command line?

There’s been problems with text-davinci-003 the last few days as shown on the status page. Might be a temporary SSL cert problem on their end.

Does your code work with another model?

1 Like

Does not work with any model :S
Always the same error…

I updated all the packages.

Could it have to do with the fact that I am working with a portable version of Python (WinPython)?

That’s your problem, I believe…

post https://api.openai.com/v1/completions

Then send it a model parameter with a current model.

What version of openai package do you have?

https://beta.openai.com/docs/api-reference/completions/create

Version 0.25.0

I’m going to try to do what you said…

A new error from command line…

Yeah, looks like 0.26.0 is current… Released: Jan 6, 2023

Is Playground working for you? Is your key valid?

I just upgraded to version 0.26.0 and I get the same error…

I have tested Playground and it works correctly :S

image

I can’t connect to the API, not even with the simple example in the download documentation…

Going back to the original problem, I’m wondering if this is it…

You’re not MacOSX, but maybe something similar is happening with your OS…

Sorry I couldn’t be of more help. Just trying to help you troubleshoot.

2 Likes

@aporelpan Hope you will be fine.

You need to enable tls, tls1 and tls2 before requesting resources here is the C# snippet

System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12;

If still any queries please ask. Thanks

2 Likes

Thanks for all the help. I will keep trying!

Hi @freelancer.nak , I am not the administrator of my computer. As soon as I get it enabled I will let you know if it has worked.

Thanks!

1 Like

Solved. I had to get the certificates from www.api.openai.com, copy them, and paste them into the Python cacert.pem file.

@PaulBellow, @freelancer.nak, thank you very much for the help.

2 Likes

Hi … the link you shared to get certificates is not working.