[GH-ISSUE #3696] SSLCertVerificationError when adding HTTPS openai api url #13352

Closed
opened 2026-04-19 20:07:12 -05:00 by GiteaMirror · 2 comments
Owner

Originally created by @jtc1246 on GitHub (Jul 7, 2024).
Original GitHub issue: https://github.com/open-webui/open-webui/issues/3696

Bug Report

Description

Bug Summary:

ERROR:apps.openai.main:Connection error: Cannot connect to host api.openai.com:443 ssl:True [SSLCertVerificationError: (1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1006)')] When tring to add openai api key and url.

But it has the ability to judge whether an openai api key is correct. (If I input a correct key, it will show Server connection verified, if input an incorrect key, it will show OpenAI: Network Problem) So this is very strange.

And api url with http is always ok.

Steps to Reproduce:
Go to Admin Panel / Settings / Connection, set api key and url. (my url is just https://api.openai.com/v1)

Expected Behavior:
Can add openai's models.

Actual Behavior:
ERROR:apps.openai.main:Connection error: Cannot connect to host api.openai.com:443 ssl:True [SSLCertVerificationError: (1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1006)')]
And no openai models shown.

Environment

  • Open WebUI Version: v0.3.7

  • Ollama (if applicable): 0.1.48

  • Operating System: macos 14.1.1 (23B81)

  • Browser (if applicable): chrome 125.0.6422.142 (Official Build) (arm64)

Reproduction Details

Confirmation:

  • I have read and followed all the instructions provided in the README.md.
  • I am on the latest version of both Open WebUI and Ollama.
  • I have included the browser console logs.
  • I have included the Docker container logs.

Logs and Screenshots

Browser Console Logs:
Screenshot 2024-07-08 at 02 43 08

Docker Container Logs:

INFO:     127.0.0.1:63732 - "GET /openai/models/0 HTTP/1.1" 200 OK
INFO:apps.openai.main:get_all_models()
ERROR:apps.openai.main:Connection error: Cannot connect to host api.openai.com:443 ssl:True [SSLCertVerificationError: (1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1006)')]
INFO:apps.ollama.main:get_all_models()
INFO:     127.0.0.1:63732 - "GET /api/models HTTP/1.1" 200 OK
INFO:apps.openai.main:get_all_models()
ERROR:apps.openai.main:Connection error: Cannot connect to host api.openai.com:443 ssl:True [SSLCertVerificationError: (1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1006)')]
INFO:config:Saving 'OPENAI_API_BASE_URLS' to config.json
INFO:     127.0.0.1:63959 - "POST /openai/urls/update HTTP/1.1" 200 OK
INFO:config:Saving 'OPENAI_API_KEYS' to config.json
INFO:     127.0.0.1:63959 - "POST /openai/keys/update HTTP/1.1" 200 OK
ERROR:apps.openai.main:401 Client Error: Unauthorized for url: https://api.openai.com/v1/models
Traceback (most recent call last):  // here is just input the incorrect openai api key
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/apps/openai/main.py", line 324, in get_models
    r.raise_for_status()
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/requests/models.py", line 1024, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 401 Client Error: Unauthorized for url: https://api.openai.com/v1/models
INFO:     127.0.0.1:63959 - "GET /openai/models/0 HTTP/1.1" 500 Internal Server Error
INFO:apps.openai.main:get_all_models()
ERROR:apps.openai.main:Connection error: Cannot connect to host api.openai.com:443 ssl:True [SSLCertVerificationError: (1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1006)')]
INFO:apps.ollama.main:get_all_models()
INFO:     127.0.0.1:63959 - "GET /api/models HTTP/1.1" 200 OK

Screenshots (if applicable):
[Attach any relevant screenshots to help illustrate the issue]

Installation Method

pip

Additional Information

I have tried using requests in this python, no ssl certificate problem.

>>> response = requests.get("https://www.google.com")
>>> print(response.status_code)
200
>>> response = requests.get("https://api.openai.com")
>>> print(response.status_code)
421

Note

If the bug report is incomplete or does not follow the provided instructions, it may not be addressed. Please ensure that you have followed the steps outlined in the README.md and troubleshooting.md documents, and provide all necessary information for us to reproduce and address the issue. Thank you!

Originally created by @jtc1246 on GitHub (Jul 7, 2024). Original GitHub issue: https://github.com/open-webui/open-webui/issues/3696 # Bug Report ## Description **Bug Summary:** ERROR:apps.openai.main:Connection error: Cannot connect to host api.openai.com:443 ssl:True [SSLCertVerificationError: (1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1006)')] When tring to add openai api key and url. But it has the ability to judge whether an openai api key is correct. (If I input a correct key, it will show Server connection verified, if input an incorrect key, it will show OpenAI: Network Problem) So this is very strange. And api url with http is always ok. **Steps to Reproduce:** Go to Admin Panel / Settings / Connection, set api key and url. (my url is just https://api.openai.com/v1) **Expected Behavior:** Can add openai's models. **Actual Behavior:** ERROR:apps.openai.main:Connection error: Cannot connect to host api.openai.com:443 ssl:True [SSLCertVerificationError: (1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1006)')] And no openai models shown. ## Environment - **Open WebUI Version:** v0.3.7 - **Ollama (if applicable):** 0.1.48 - **Operating System:** macos 14.1.1 (23B81) - **Browser (if applicable):** chrome 125.0.6422.142 (Official Build) (arm64) ## Reproduction Details **Confirmation:** - [x] I have read and followed all the instructions provided in the README.md. - [x] I am on the latest version of both Open WebUI and Ollama. - [x] I have included the browser console logs. - [x] I have included the Docker container logs. ## Logs and Screenshots **Browser Console Logs:** <img width="1020" alt="Screenshot 2024-07-08 at 02 43 08" src="https://github.com/open-webui/open-webui/assets/43341500/2c6040cc-7cf1-49a6-a70d-470c4dab02de"> **Docker Container Logs:** ``` INFO: 127.0.0.1:63732 - "GET /openai/models/0 HTTP/1.1" 200 OK INFO:apps.openai.main:get_all_models() ERROR:apps.openai.main:Connection error: Cannot connect to host api.openai.com:443 ssl:True [SSLCertVerificationError: (1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1006)')] INFO:apps.ollama.main:get_all_models() INFO: 127.0.0.1:63732 - "GET /api/models HTTP/1.1" 200 OK INFO:apps.openai.main:get_all_models() ERROR:apps.openai.main:Connection error: Cannot connect to host api.openai.com:443 ssl:True [SSLCertVerificationError: (1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1006)')] INFO:config:Saving 'OPENAI_API_BASE_URLS' to config.json INFO: 127.0.0.1:63959 - "POST /openai/urls/update HTTP/1.1" 200 OK INFO:config:Saving 'OPENAI_API_KEYS' to config.json INFO: 127.0.0.1:63959 - "POST /openai/keys/update HTTP/1.1" 200 OK ERROR:apps.openai.main:401 Client Error: Unauthorized for url: https://api.openai.com/v1/models Traceback (most recent call last): // here is just input the incorrect openai api key File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/apps/openai/main.py", line 324, in get_models r.raise_for_status() File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/requests/models.py", line 1024, in raise_for_status raise HTTPError(http_error_msg, response=self) requests.exceptions.HTTPError: 401 Client Error: Unauthorized for url: https://api.openai.com/v1/models INFO: 127.0.0.1:63959 - "GET /openai/models/0 HTTP/1.1" 500 Internal Server Error INFO:apps.openai.main:get_all_models() ERROR:apps.openai.main:Connection error: Cannot connect to host api.openai.com:443 ssl:True [SSLCertVerificationError: (1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1006)')] INFO:apps.ollama.main:get_all_models() INFO: 127.0.0.1:63959 - "GET /api/models HTTP/1.1" 200 OK ``` **Screenshots (if applicable):** [Attach any relevant screenshots to help illustrate the issue] ## Installation Method pip ## Additional Information I have tried using requests in this python, no ssl certificate problem. ``` >>> response = requests.get("https://www.google.com") >>> print(response.status_code) 200 >>> response = requests.get("https://api.openai.com") >>> print(response.status_code) 421 ``` ## Note If the bug report is incomplete or does not follow the provided instructions, it may not be addressed. Please ensure that you have followed the steps outlined in the README.md and troubleshooting.md documents, and provide all necessary information for us to reproduce and address the issue. Thank you!
Author
Owner

@jtc1246 commented on GitHub (Jul 7, 2024):

Solved by following:

In site-packages/apps/openai/main.py, change 2 functions.

In async def fetch_url(url, key):, line about 191, change

        async with aiohttp.ClientSession(timeout=timeout, trust_env=True) as session:

to

        connector = aiohttp.TCPConnector(ssl=False)
        async with aiohttp.ClientSession(timeout=timeout, trust_env=True, connector=connector) as session:

In async def generate_chat_completion(, line about 466, change

try:
        session = aiohttp.ClientSession(trust_env=True)

to

try:
        connector = aiohttp.TCPConnector(ssl=False)
        session = aiohttp.ClientSession(trust_env=True, connector=connector)
<!-- gh-comment-id:2212544812 --> @jtc1246 commented on GitHub (Jul 7, 2024): Solved by following: In site-packages/apps/openai/main.py, change 2 functions. In async def fetch_url(url, key):, line about 191, change ``` async with aiohttp.ClientSession(timeout=timeout, trust_env=True) as session: ``` to ``` connector = aiohttp.TCPConnector(ssl=False) async with aiohttp.ClientSession(timeout=timeout, trust_env=True, connector=connector) as session: ``` In async def generate_chat_completion(, line about 466, change ``` try: session = aiohttp.ClientSession(trust_env=True) ``` to ``` try: connector = aiohttp.TCPConnector(ssl=False) session = aiohttp.ClientSession(trust_env=True, connector=connector) ```
Author
Owner

@justinh-rahb commented on GitHub (Jul 7, 2024):

Ya that's not going to be patched in, you've disabled SSL verification. There's no bug here, if this was an issue it'd be immediately noticed by every developer before it ever hit main branch. I'd instead wonder why your SSL is failing to verify.. maybe your traffic is being MITM'd? 🤷‍♂️

<!-- gh-comment-id:2212594054 --> @justinh-rahb commented on GitHub (Jul 7, 2024): Ya that's not going to be patched in, you've disabled SSL verification. There's no bug here, if this was an issue it'd be immediately noticed by every developer before it ever hit `main` branch. I'd instead wonder why your SSL is failing to verify.. maybe your traffic is being MITM'd? 🤷‍♂️
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/open-webui#13352