728x90
반응형
OpenAPI 사용하다가 SSL 에러가 발생했다. 구글링을 해서 찾은 방법들을 몇가지 적용해봐도 해결되지는 않았다. 내용들 중에 결론은 request 를 사용시 verify 를 False 로 해야 한다는 것이었다. 그래서 에러 로그를 다시 봤다.
Traceback (most recent call last):
File "c:\workspace\.venv\Lib\site-packages\httpx\_transports\default.py", line 69, in map_httpcore_exceptions
yield
File "c:\workspace\.venv\Lib\site-packages\httpx\_transports\default.py", line 233, in handle_request
resp = self._pool.handle_request(req)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "c:\workspace\.venv\Lib\site-packages\httpcore\_sync\connection_pool.py", line 216, in handle_request
raise exc from None
File "c:\workspace\.venv\Lib\site-packages\httpcore\_sync\connection_pool.py", line 196, in handle_request
response = connection.handle_request(
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "c:\workspace\.venv\Lib\site-packages\httpcore\_sync\http_proxy.py", line 317, in handle_request
stream = stream.start_tls(**kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "c:\workspace\.venv\Lib\site-packages\httpcore\_sync\http11.py", line 383, in start_tls
return self._stream.start_tls(ssl_context, server_hostname, timeout)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "c:\workspace\.venv\Lib\site-packages\httpcore\_backends\sync.py", line 152, in start_tls
with map_exceptions(exc_map):
File "C:\Users\sanghyun0910.kim\AppData\Local\Programs\Python\Python311\Lib\contextlib.py", line 158, in __exit__
self.gen.throw(typ, value, traceback)
File "c:\workspace\.venv\Lib\site-packages\httpcore\_exceptions.py", line 14, in map_exceptions
raise to_exc(exc) from exc
httpcore.ConnectError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1006)
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "c:\workspace\.venv\Lib\site-packages\openai\_base_client.py", line 972, in _request
response = self._client.send(
^^^^^^^^^^^^^^^^^^
File "c:\workspace\.venv\Lib\site-packages\httpx\_client.py", line 914, in send
response = self._send_handling_auth(
^^^^^^^^^^^^^^^^^^^^^^^^^
File "c:\workspace\.venv\Lib\site-packages\httpx\_client.py", line 942, in _send_handling_auth
response = self._send_handling_redirects(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "c:\workspace\.venv\Lib\site-packages\httpx\_client.py", line 979, in _send_handling_redirects
response = self._send_single_request(request)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "c:\workspace\.venv\Lib\site-packages\httpx\_client.py", line 1015, in _send_single_request
response = transport.handle_request(request)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "c:\workspace\.venv\Lib\site-packages\httpx\_transports\default.py", line 232, in handle_request
with map_httpcore_exceptions():
File "C:\Users\sanghyun0910.kim\AppData\Local\Programs\Python\Python311\Lib\contextlib.py", line 158, in __exit__
self.gen.throw(typ, value, traceback)
File "c:\workspace\.venv\Lib\site-packages\httpx\_transports\default.py", line 86, in map_httpcore_exceptions
raise mapped_exc(message) from exc
httpx.ConnectError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1006)
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "c:\workspace\my-ai\chat_completion.py", line 10, in <module>
completion = client.chat.completions.create(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "c:\workspace\.venv\Lib\site-packages\openai\_utils\_utils.py", line 274, in wrapper
return func(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^
File "c:\workspace\.venv\Lib\site-packages\openai\resources\chat\completions.py", line 650, in create
return self._post(
^^^^^^^^^^^
File "c:\workspace\.venv\Lib\site-packages\openai\_base_client.py", line 1259, in post
return cast(ResponseT, self.request(cast_to, opts, stream=stream, stream_cls=stream_cls))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "c:\workspace\.venv\Lib\site-packages\openai\_base_client.py", line 936, in request
return self._request(
^^^^^^^^^^^^^^
File "c:\workspace\.venv\Lib\site-packages\openai\_base_client.py", line 996, in _request
return self._retry_request(
^^^^^^^^^^^^^^^^^^^^
File "c:\workspace\.venv\Lib\site-packages\openai\_base_client.py", line 1074, in _retry_request
return self._request(
^^^^^^^^^^^^^^
File "c:\workspace\.venv\Lib\site-packages\openai\_base_client.py", line 996, in _request
return self._retry_request(
^^^^^^^^^^^^^^^^^^^^
File "c:\workspace\.venv\Lib\site-packages\openai\_base_client.py", line 1074, in _retry_request
return self._request(
^^^^^^^^^^^^^^
File "c:\workspace\.venv\Lib\site-packages\openai\_base_client.py", line 1006, in _request
raise APIConnectionError(request=request) from err
openai.APIConnectionError: Connection error.
위 내용중에 이런 내용이 있다.
File "c:\workspace\.venv\Lib\site-packages\httpx\_client.py", line 979, in _send_handling_redirects
response = self._send_single_request(request)
그래서 일단 위 경로의 _client.py 파일을 찾았다. 그리고 확인해보니 init 항목에 verify 가 default 로 True 로 되어있었다. 그래서 그부분을 False 로 고치고 실행을 시키니 정상 동작을 했다.
def __init__(
self,
*,
auth: AuthTypes | None = None,
params: QueryParamTypes | None = None,
headers: HeaderTypes | None = None,
cookies: CookieTypes | None = None,
verify: VerifyTypes = False,
728x90
반응형
'Development > Python' 카테고리의 다른 글
Python 웹 스크래핑 하기2 (1) | 2024.10.17 |
---|---|
Python 웹 스크래핑 하기 (0) | 2024.08.20 |
[Python] Blob Storage 에 Connection String 으로 연결하기 (0) | 2024.08.01 |
python 으로 Azure blob storage 연결 (0) | 2024.07.12 |
poetry 설정 및 패키지 추가 (0) | 2024.07.11 |