[μ€λ₯ν΄κ²°] osX + python3 + SSL certificate Error
π 3 mins read
# SSLCertVerificationError
osX + python3.X μμ μΌλΆ λͺ¨λ λ΄μμ λ°μ΄ν°λ₯Ό λ€μ΄λ‘λ λ°κ±°λ νλ κ²½μ°μ κ°λ λ³Ό μ μλ μ€λ₯μ λλ€.
SSL μΈμ¦μ μ€λ₯λ¬Έμ μΈλ°, λ€μκ³Ό κ°μ΄ python3.X μμ, νμ΄μ¬ λͺ¨λλ‘ λ°μ΄ν°λ₯Ό λ€μ΄λ‘λ λ°λ κ²½μ°μ μ£Όλ‘ λ°μν©λλ€.
(λ¬Όλ‘ SSL μΈμ¦μλ₯Ό μꡬνλ ν΅μ μ΄λΌλ©΄ κΌ λ°μ΄ν°λ₯Ό λ€μ΄ λ°μλκ° μλμλ μκ² μ£ ?)
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/urllib/request.py", line 1350, in do_open
encode_chunked=req.has_header('Transfer-encoding'))
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/http/client.py", line 1277, in request
self._send_request(method, url, body, headers, encode_chunked)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/http/client.py", line 1323, in _send_request
self.endheaders(body, encode_chunked=encode_chunked)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/http/client.py", line 1272, in endheaders
self._send_output(message_body, encode_chunked=encode_chunked)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/http/client.py", line 1032, in _send_output
self.send(msg)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/http/client.py", line 972, in send
self.connect()
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/http/client.py", line 1447, in connect
server_hostname=server_hostname)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/ssl.py", line 423, in wrap_socket
session=session
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/ssl.py", line 870, in _create
self.do_handshake()
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/ssl.py", line 1139, in do_handshake
self._sslobj.do_handshake()
ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1091)
- μμ μμμ κ²½μ° λ§₯λΆμμ korporaλΌμ΄λΈλ¬λ¦¬λ‘ νκ΅μ΄ μ½νΌμ€λ₯Ό λ€μ΄ λ°μλ λ°μν λ‘κ·ΈμΈλ°μ,
# Solution
"Finder"μμ "Applications/python3.X/Install Certificates.command" μ€ν¬λ¦½νΈ νμΌμ μ§μ μ€ν ν΄μ£Όκ±°λ,

μλμ bash μ€ν¬λ¦½νΈλ₯Ό μ€ννλ©΄ λ©λλ€.
(κ°μ λ΄μ©μ
λλ€. λ€λ§, python3.Xμ ν΄λΉ κ²½λ‘μ λ§κ² μμ νμ)
#!/bin/sh
/Library/Frameworks/Python.framework/Versions/3.7/bin/python3.7 << "EOF"
# install_certifi.py
#
# sample script to install or update a set of default Root Certificates
# for the ssl module. Uses the certificates provided by the certifi package:
# https://pypi.org/project/certifi/
import os
import os.path
import ssl
import stat
import subprocess
import sys
STAT_0o775 = ( stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR
| stat.S_IRGRP | stat.S_IWGRP | stat.S_IXGRP
| stat.S_IROTH | stat.S_IXOTH )
def main():
openssl_dir, openssl_cafile = os.path.split(
ssl.get_default_verify_paths().openssl_cafile)
print(" -- pip install --upgrade certifi")
subprocess.check_call([sys.executable,
"-E", "-s", "-m", "pip", "install", "--upgrade", "certifi"])
import certifi
# change working directory to the default SSL directory
os.chdir(openssl_dir)
relpath_to_certifi_cafile = os.path.relpath(certifi.where())
print(" -- removing any existing file or link")
try:
os.remove(openssl_cafile)
except FileNotFoundError:
pass
print(" -- creating symlink to certifi certificate bundle")
os.symlink(relpath_to_certifi_cafile, openssl_cafile)
print(" -- setting permissions")
os.chmod(openssl_cafile, STAT_0o775)
print(" -- update complete")
if __name__ == '__main__':
main()
EOF
SSL μΈμ¦μ μ€μΉ νμ μ½νΌμ€ λ€μ΄λ‘λλ μ μλνλ λͺ¨μ΅μ λλ€.
(korpora).venv β― korpora fetch --corpus korean_petitions
## Arguments of Korpora CLI ##
- corpus : ['korean_petitions']
- force_download : False
- func : fetch
- root : None
[korean_petitions] download petitions_2017-08: 1.84MB [00:00, 7.06MB/s]
[korean_petitions] download petitions_2017-09: 20.4MB [00:01, 11.0MB/s]
[korean_petitions] download petitions_2017-10: 12.0MB [00:00, 20.6MB/s]
[korean_petitions] download petitions_2017-11: 28.4MB [00:01, 27.6MB/s]
[korean_petitions] download petitions_2017-12: 29.0MB [00:00, 29.8MB/s]
[korean_petitions] download petitions_2018-01: 43.9MB [00:01, 29.7MB/s]
[korean_petitions] download petitions_2018-02: 33.8MB [00:01, 31.6MB/s]
[korean_petitions] download petitions_2018-03: 34.3MB [00:01, 22.0MB/s]
[korean_petitions] download petitions_2018-04: 35.5MB [00:01, 30.5MB/s]
[korean_petitions] download petitions_2018-05: 37.5MB [00:01, 24.1MB/s]
[korean_petitions] download petitions_2018-06: 37.8MB [00:01, 32.5MB/s]
[korean_petitions] download petitions_2018-07: 40.5MB [00:01, 33.1MB/s]
[korean_petitions] download petitions_2018-08: 39.8MB [00:01, 32.1MB/s]
[korean_petitions] download petitions_2018-09: 36.1MB [00:01, 29.6MB/s]
[korean_petitions] download petitions_2018-10: 38.1MB [00:01, 29.6MB/s]
[korean_petitions] download petitions_2018-11: 37.7MB [00:01, 31.7MB/s]
[korean_petitions] download petitions_2018-12: 33.0MB [00:00, 34.5MB/s]
[korean_petitions] download petitions_2019-01: 34.8MB [00:02, 13.6MB/s]
[korean_petitions] download petitions_2019-02: 30.8MB [00:01, 19.2MB/s]
[korean_petitions] download petitions_2019-03: 34.9MB [00:01, 28.8MB/s]