Skip to content

Commit 701a0f1

Browse files
committed
Disable SSL verification for api.openai.com domain (Python 3.10 doesn't have certs?)
1 parent 3abbaf1 commit 701a0f1

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

git-grok

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import random
99
import re
1010
import shlex
1111
import signal
12+
import ssl
1213
import subprocess
1314
import sys
1415
import traceback
@@ -20,7 +21,7 @@ from threading import Thread, current_thread, main_thread
2021
from time import time, sleep
2122
from typing import Any, Callable, Literal, TypeVar, Generic, cast
2223
from urllib.request import Request, urlopen
23-
from urllib.error import HTTPError
24+
from urllib.error import HTTPError, URLError
2425

2526
BRANCH_PREFIX = "grok/"
2627
PR_HEADER = "Pull Request"
@@ -1441,7 +1442,13 @@ class Main:
14411442
res = None
14421443
returncode = None
14431444
try:
1444-
with urlopen(req) as res:
1445+
# MacOS Python 3.10 doesn't seem to have OpenAI certs. It raises the
1446+
# error: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed:
1447+
# unable to get local issuer certificate.
1448+
context = ssl.create_default_context()
1449+
context.check_hostname = False
1450+
context.verify_mode = ssl.CERT_NONE
1451+
with urlopen(req, context=context) as res:
14451452
res = json.load(res)
14461453
res = str(res["choices"][0]["message"]["content"].strip())
14471454
parts = [part.strip() for part in res.split(AI_SEPARATOR)]
@@ -1455,6 +1462,9 @@ class Main:
14551462
res = e.read().decode()
14561463
returncode = e.code
14571464
raise UserException(f"{e.code} {e.reason}: {res}")
1465+
except URLError as e:
1466+
returncode = -1
1467+
raise UserException(f"Network error: {e}")
14581468
finally:
14591469
self.debug_log_shell_command(
14601470
cmd=["curl", "-X", "POST", req.full_url],

0 commit comments

Comments
 (0)