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.
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
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