[youtube-dl] python3 SSL error (CERTIFICATE_VERIFY_FAILED)

background

If you hit the youtube-dl command as follows, you may get the error SSL: CERTIFICATE_VERIFY_FAILED. I will write the cause and solution for that.

youtube-dl `url`

ERROR: Unable to download webpage: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1045)> (caused by URLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1045)')))

Apparently, due to a bug in pyhon3.6, the certificate path may not pass. If you are interested in the details of the bug, the bug tracker for python3.6 is here.

Solution 1

The easiest way is to communicate over HTTP if there is an error with SSL. You can download without SSL certificate by adding the --no-check-certificate option to the command.

youtube-dl `url` --no-check-certificate

Solution 2

After all, some people may think that it is better to communicate with SSL. The certificate path doesn't pass, so all you have to do is pass it.

A package called certifi will easily tell you the location of the python3.6 certificate.

pip3 install --upgrade certifi

Simply ask for the path with the python3 interpreter.

>>> import certifi
>>> certifi.where()
'/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/certifi/cacert.pem'

Now that you know the location of the pem file (SSL certificate), pass it through the path.

export SSL_CERT_FILE=/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/certifi/cacert.pem

Now that the path is passed, you can use the youtube-dl command without any SSL error. Since it is an export, it may be convenient to write it in bashrc or zshrc.

Reference

StackOverflow Certificate Verification Failure for youtube-dl

SSL certificate verify failed #4816

Recommended Posts

[youtube-dl] python3 SSL error (CERTIFICATE_VERIFY_FAILED)
Python Error Handling
Python Not Implemented Error
Today's python error: killed
[Python] for statement error
[Python] SQLAlchemy error avoidance memorandum
Aim python library master (66) youtube-dl
What to do when "SSL: CERTIFICATE_VERIFY_FAILED _ssl.c: 1056" appears in Python
Error when playing with python
#python Python Japanese syntax error avoidance
Slice error in python (´ ; ω ; `)
Error resolution python version check
Use youtube_dl as a python module. appendix) Nico Nico Douga HTTP 403 error
[python] Error when installing library ramkan
Today's python error: SyntaxError Non-ASCII character
Disable python2.6 ssl3 protocol in centos6
A pretty sloppy Python error solution
Today's python error: image is blank
Python error detection run from Powershell
Solution if pip gives [SSL: CERTIFICATE_VERIFY_FAILED]
Strange and horrifying Python error story
[Python] What to do when an error related to SSL authentication is returned