30

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?

  • 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). – Charles Duffy Feb 10 '20 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. – Charles Duffy Feb 10 '20 at 20:47
  • @CharlesDuffy how can I fix this? –  Feb 10 '20 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? – Charles Duffy Feb 10 '20 at 20:49

1 Answers1

94

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

Daniel Kamil Kozar
  • 18,476
  • 5
  • 50
  • 64
nt4
  • 974
  • 6
  • 4
  • 5
    ...if you don't care about whether the site you're connecting to claiming to be YouTube is in fact the real thing. – Charles Duffy Feb 10 '20 at 20:49
  • Where do I add this since I run it in IDLE? –  Feb 10 '20 at 21:09
  • 3
    Reading https://github.com/ytdl-org/youtube-dl/blob/master/youtube_dl/__init__.py, 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). – Charles Duffy Feb 10 '20 at 21:32
  • 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. – nt4 Feb 10 '20 at 23:46
  • does this mean YouTube-dl uses `wget` internally? I tried `--external-downloader` and still no good – lang2 Oct 10 '20 at 03:11
  • I added `--no-check-certificate` but got `[youtube] bDhpwNiOHUo: Downloading webpage ERROR: bDhpwNiOHUo: YouTube said: Unable to extract video data` – ecjb Mar 07 '21 at 11:44
  • Needless to say don't pass any credentials when using --no-check-certificate. Otherwise it should be fine. @ecjb With an error like that, youtubedl probably needs to be updated. (-U) – Z. Cochrane Jul 11 '21 at 17:57
  • @CharlesDuffy: I've run into the same problem as the OP and I'd certainly like to fix my system's CA certificate list. However, I have no idea where and how to start with that. Do you happen to have any pointers towards achieving such a goal? – René Nyffenegger Feb 12 '22 at 21:07
  • to which command? this is a python script where someone does `import ...` – Matthias Burger Mar 26 '22 at 10:24