31

I ran this code in Python:

from __future__ import unicode_literals
import youtube_dl


ydl_opts = {
    'format': 'bestaudio/best',
    'postprocessors': [{
        'key': 'FFmpegExtractAudio',
        'preferredcodec': 'mp3',
        'preferredquality': '192',
    }],
}
with youtube_dl.YoutubeDL(ydl_opts) as ydl:
    ydl.download(['YOUTUBE URL'])

I was hoping it would convert the Youtube video to a URL file.

I got a really long error which basically repeated this:

[0;31mERROR:[0m Unable to download webpage: (caused by URLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1108)')))

I have searched online but a unsure on how to solve this problem?

4
  • 1
    Means exactly what it said -- the list of CA certificates backing your Python interpreter's SSL implementation doesn't include a CA signing the certificate used by the server for the site purporting to be YouTube (this could mean your local CA certs are out-of-date, or it could mean that your Internet connection is having connections to YouTube intercepted and replaced with some other site, possibly something that pretends to be YouTube but injects hostile javascript). Commented Feb 10, 2020 at 20:47
  • 1
    ...it's not a problem with your code, so I don't know what you expect us to do here. Talk to your friendly local sysadmin; how to update the CA cert list varies by operating system / Linux distro / etc. Commented Feb 10, 2020 at 20:47
  • @CharlesDuffy how can I fix this? Commented Feb 10, 2020 at 20:47
  • I take it by that question that you don't have a friendly local sysadmin? First question: Which operating system are you running? Commented Feb 10, 2020 at 20:49

1 Answer 1

100

Add the no-check-certificate parameter to the command:

youtube-dl --no-check-certificate

This option was renamed to --no-check-certificates starting with version 2021.10.09 (inclusive).

Sign up to request clarification or add additional context in comments.

9 Comments

...if you don't care about whether the site you're connecting to claiming to be YouTube is in fact the real thing.
Where do I add this since I run it in IDLE?
Reading github.com/ytdl-org/youtube-dl/blob/master/youtube_dl/…, the plain reading is that you should probably set 'no_check_certificate': True in ydl_opts if you want this workaround -- which, again, I strongly recommend against; better to fix your system's CA certificate list (if that's the problem), or find the source of whatever monkey-in-the-middle is intercepting connections to YouTube (if it's that).
just make sure the site you are connecting to is legit. I use youtube-dl with ffmeg to download some videos from other sites, which I know are legit, so I use this switch oftem.
to which command? this is a python script where someone does import ...
|