Certificate_verify_failed

I have code in my app that creates a certificate. That is is here:

SCRIPT_DIR = Path(__file__).parent.absolute()

def resource_path(relative_path):
    if hasattr(sys, '_MEIPASS'):
        return os.path.join(sys._MEIPASS, relative_path)
    return os.path.join(SCRIPT_DIR, relative_path)

def make_full_pem_cert_path(*certs):
    certifi_pem_path = certifi.where()
    cert_contents = ""

    with open(certifi_pem_path, 'r') as f:
        cert_contents += f.read()

    for cert in certs:
        with open(cert, 'r') as f:
            cert_contents += f.read()

    # Create file in script directory
    full_cert_path = os.path.join(SCRIPT_DIR, 'full_cert.pem')
    with open(full_cert_path, 'w') as f:
        f.write(cert_contents)

    return full_cert_path

# Obtain full path to the certs in script bundle
local_cert_path = resource_path('SherbotAI.cer')
openai_cert_path = resource_path('SSL_certificate.crt')

PEM_PATH = make_full_pem_cert_path(local_cert_path, openai_cert_path)
os.environ['REQUESTS_CA_BUNDLE'] = PEM_PATH

The code I used to send a request to the OpenAI servers is here (and it works):

def getGPTResponse(input_text, gpt_model, stream=False):
    response = openai.ChatCompletion.create(
        model=gpt_model,
        messages=[{
                "role": "system",
                "content": input_text}],
        stream=stream
    )
    return response['choices'][0]['message']['content']

However, now I use the following code in the latest API release:

def getGPTResponse(input_text, gpt_model, stream=False):
    client = OpenAI()

    response = client.chat.completions.create(
        model=gpt_model,
        messages=[{
                "role": "system",
                "content": input_text}],
        stream=False
    )
    return response.choices[0].message.content

Which causes the certification to fail. What is causing this failure? Please help.

I have managed to solve it with this code, in case anyone finds it useful:

def getGPTResponse(input_text, gpt_model, stream=False):
    # Initialize the httpx.Client with the bundled .pem file
    http_client = httpx.Client(verify='full_cert.pem')

    # Initialize the OpenAI client with the custom httpx.Client
    client = OpenAI(http_client=http_client)

    # Make the API call with the provided text and model
    response = client.chat.completions.create(
        model=gpt_model,
        messages=[{
            "role": "system",
            "content": input_text
        }],
        stream=stream
    )

    # Return the content of the API response
    return response.choices[0].message.content