본문 바로가기
IT/Python

Python Error - SSLCertVerificationError

by 큰공 2021. 11. 11.
728x90
반응형

 

들어가며

 파이썬 에러 파헤치기입니다.

 윈도우10 환경에서 잘 되던 코드인데, 동일한 코드를 Mac OS 에서 실행 할려고 하니, 아래와 같은 처음 보는 에러가 발생하였습니다.

 

ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1123)

 

traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/websockets/legacy/client.py", line 649, in __await_impl_timeout__
    return await asyncio.wait_for(self.__await_impl__(), self.open_timeout)
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/asyncio/tasks.py", line 483, in wait_for
    return fut.result()
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/websockets/legacy/client.py", line 653, in __await_impl__
    transport, protocol = await self._create_connection()
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/asyncio/base_events.py", line 1050, in create_connection
    transport, protocol = await self._create_connection_transport(
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/asyncio/base_events.py", line 1080, in _create_connection_transport
    await waiter
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/asyncio/sslproto.py", line 529, in data_received
    ssldata, appdata = self._sslpipe.feed_ssldata(data)
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/asyncio/sslproto.py", line 189, in feed_ssldata
    self._sslobj.do_handshake()
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/ssl.py", line 944, in do_handshake
    self._sslobj.do_handshake()
ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1123)

 

원인

 인터넷 연결이 필요하여, Web Sockect 으로 크롤링 하는 동작 부분에서 HTTPS 가 정상적으로 지원하지 않아서 발생하는 현상으로 파악됩니다.

 

 같은 네트워크 기반에서도 OS 환경에 따라서 에러 발생이 달라지는걸로 봐서는 코드나 네트워크 환경에 대한 문제가 아니라 개발 환경 의 문제입니다.

 

해결 방안

 1) pip install --upgrade certifi

 certifi 패키지를 업그레이드 하는 방법입니다.

bash-3.2$ pip install --upgrade certifi 
Requirement already up-to-date: certifi in 
/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages (2021.10.8)
WARNING: You are using pip version 20.2.2; however, version 21.3.1 is available.
You should consider upgrading via the 
'/Library/Frameworks/Python.framework/Versions/3.8/bin/python3 -m 
pip install --upgrade pip' command.

 

 이미 certifi 패키지는 최신으로 되어있으나, pip 자체를 업그레이드 하라고 하네요

 

 2) pip install --upgrade pip

 pip 자체를 업그레이드 해봅니다.

bash-3.2$ pip install --upgrade pip
Collecting pip
  Downloading pip-21.3.1-py3-none-any.whl (1.7 MB)
     |████████████████████████████████| 1.7 MB 5.0 MB/s 
Installing collected packages: pip
  Attempting uninstall: pip
    Found existing installation: pip 20.2.2
    Uninstalling pip-20.2.2:
      Successfully uninstalled pip-20.2.2
Successfully installed pip-21.3.1

 여기까지 해도 해결은 되지 않았습니다.

 

 3) Install certificates.command

 파이썬 설치 경로에서 Install Certificates.command 파일을 찾아서 실행해 줍니다.

 간단하게 Command + Space 로 Install Certificates.command 를 찾고, 이를 더블클릭으로 실행해주면 됩니다.

 

 

 

 

이제 더이상 Mac OS 에서 ssl.SSLCertVerificationError 가 뜨지 않음을 확인 할 수 있습니다.

 

ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1123)

 

 

728x90
반응형

댓글