Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
AI and LLM integration

Azure OpenAI fails with an SSL certificate verification error

Errorhttpx.ConnectError: [SSL: CERTIFICATE_VERIFY_FAILED]

Short answer

The client checks the endpoint's certificate against its CA bundle, which is certifi by default. If a company proxy re-signs HTTPS traffic with its own CA, the check fails with CERTIFICATE_VERIFY_FAILED. Give the client the proxy's CA file through SSL_CERT_FILE, or build an SSL context from the system store. Do not set verify to False.

  • Applies to openai Python SDK 1.x, httpx 0.27 and later, Python 3.12
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    See who signed the certificate your machine receives from the endpoint. A company name instead of Microsoft means a proxy sits in the middle.

    openssl s_client -connect example-endpoint.openai.azure.com:443 -servername example-endpoint.openai.azure.com </dev/null 2>/dev/null | openssl x509 -noout -issuer
  2. 2Match what you see, then jump to its fix

    1. 1The issuer is your company or a security productA proxy re-signs HTTPS with a CA that Python does not knowFix
    2. 2The CA is installed in the OS, but Python still rejects the certificateYou need the operating system's certificate storeFix

What does the error look like?

  • httpx.ConnectError: [SSL: CERTIFICATE_VERIFY_FAILED]

Cause 1 of 2

A proxy re-signs HTTPS with a CA that Python does not know

1Check

HTTPX, which the OpenAI client uses, trusts the certifi bundle by default and respects SSL_CERT_FILE and SSL_CERT_DIR.

python -c "import certifi; print(certifi.where())"

2Fix

Get the proxy's root CA in PEM format from your IT team and point SSL_CERT_FILE at a bundle that contains it.

export SSL_CERT_FILE=/etc/ssl/certs/company-ca-bundle.pem
python app.py

3Verify

Run the request again; the verification error is gone.

python -c "from openai import AzureOpenAI; print('client ok')"

Confirmed by python-httpx.org

Did this fix it?

Cause 2 of 2

You need the operating system's certificate store

1Check

Python's HTTP stack does not use the OS store unless asked. The truststore package lets HTTPX use it.

pip show truststore

2Fix

Install truststore, and build an SSL context from it for the client you pass in.

pip install truststore

import ssl, truststore, httpx
from openai import AzureOpenAI
ctx = truststore.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
client = AzureOpenAI(
    azure_endpoint="https://example-endpoint.openai.azure.com",
    api_version="2023-07-01-preview",
    http_client=httpx.Client(verify=ctx),
)

3Verify

Send a small request with this client.

print('client built with system trust store')

Confirmed by python-httpx.org

Did this fix it?

How do I stop it coming back?

  • Treat verify=False as a debugging step on a throwaway machine, never in code that ships.
  • Keep the CA bundle path in an environment variable, not in application code.
  • Add the company CA to your Docker images when the same proxy applies in CI.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.