Error

[PYTHON] SSL : Python3을 사용하여 CERTIFICATE_VERIFY_FAILED

모딩 2020. 5. 12. 20:44
반응형

문제: 크롤링에서 urllib.request.urlopen() 이 동작하지 않습니다.  아래는 해당 오류 메세지 입니다.

Traceback (most recent call last):
  File "/Users/hyojin/Documents/git/mushroom/crawling/img_crawling.py", line 13, in <module>
    html = urlopen(url)
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/urllib/request.py", line 222, in urlopen
    return opener.open(url, data, timeout)
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/urllib/request.py", line 525, in open
    response = self._open(req, data)
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/urllib/request.py", line 542, in _open
    result = self._call_chain(self.handle_open, protocol, protocol +
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/urllib/request.py", line 502, in _call_chain
    result = func(*args)
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/urllib/request.py", line 1362, in https_open
    return self.do_open(http.client.HTTPSConnection, req,
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/urllib/request.py", line 1322, in do_open
    raise URLError(err)
urllib.error.URLError: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1108)>

 

 

해결: SSL 인증 모듈을 사용합니다. 아래의 모듈과 코드를 추가합니다. 

 

import ssl

ssl._create_default_https_context = ssl._create_unverified_context

// 기존 코드
반응형