본문 바로가기
Coding/Python

Python3 requests SSL 오류 해결 방법

by Hide­ 2018. 2. 3.
반응형

Python3 requests 라이브러리를 통해 HTTPS 웹페이지와 통신을 하던 도중 아래와 같은 에러를 만났다.


Traceback (most recent call last):

  File "/usr/local/lib/python3.6/site-packages/urllib3/connectionpool.py", line 595, in urlopen

    self._prepare_proxy(conn)

  File "/usr/local/lib/python3.6/site-packages/urllib3/connectionpool.py", line 816, in _prepare_proxy

    conn.connect()

  File "/usr/local/lib/python3.6/site-packages/urllib3/connection.py", line 326, in connect

    ssl_context=context)

  File "/usr/local/lib/python3.6/site-packages/urllib3/util/ssl_.py", line 329, in ssl_wrap_socket

    return context.wrap_socket(sock, server_hostname=server_hostname)

  File "/usr/local/Cellar/python3/3.6.2/Frameworks/Python.framework/Versions/3.6/lib/python3.6/ssl.py", line 401, in wrap_socket

    _context=self, _session=session)

  File "/usr/local/Cellar/python3/3.6.2/Frameworks/Python.framework/Versions/3.6/lib/python3.6/ssl.py", line 808, in __init__

    self.do_handshake()

  File "/usr/local/Cellar/python3/3.6.2/Frameworks/Python.framework/Versions/3.6/lib/python3.6/ssl.py", line 1061, in do_handshake

    self._sslobj.do_handshake()

  File "/usr/local/Cellar/python3/3.6.2/Frameworks/Python.framework/Versions/3.6/lib/python3.6/ssl.py", line 683, in do_handshake

    self._sslobj.do_handshake()

ssl.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:748)


ssl ~ 나오는걸로 봐서 아마 SSL관련 오류인 것 같다.

현재 내가 통신하려는 서버는 https를 사용하고 있으므로 옵션을 줘야 한다.

아래와 같이


verify=False 옵션을 주면 해결된다.


From requests documentation on SSL verification:

Requests can verify SSL certificates for HTTPS requests, just like a web browser. To check a host’s SSL certificate, you can use the verify argument:

>>> requests.get('https://kennethreitz.com', verify=True)

If you don't want to verify your SSL certificate, make verify=False


참고 : https://stackoverflow.com/questions/10667960/python-requests-throwing-sslerror