Youtubedl CERTIFICATE_VERIFY_FAILED [duplicate]
Asked Answered
A

1

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?

Accomplice answered 10/2, 2020 at 20:40 Comment(4)
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).Pip
...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.Pip
@CharlesDuffy how can I fix this?Accomplice
I take it by that question that you don't have a friendly local sysadmin? First question: Which operating system are you running?Pip
B
97

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

Bradeord answered 10/2, 2020 at 20:49 Comment(9)
...if you don't care about whether the site you're connecting to claiming to be YouTube is in fact the real thing.Pip
Where do I add this since I run it in IDLE?Accomplice
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).Pip
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.Bradeord
does this mean YouTube-dl uses wget internally? I tried --external-downloader and still no goodIneptitude
I added --no-check-certificate but got [youtube] bDhpwNiOHUo: Downloading webpage ERROR: bDhpwNiOHUo: YouTube said: Unable to extract video dataWestberg
Needless to say don't pass any credentials when using --no-check-certificate. Otherwise it should be fine. @Westberg With an error like that, youtubedl probably needs to be updated. (-U)Tiedeman
@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?Photokinesis
to which command? this is a python script where someone does import ...Strontian

© 2022 - 2024 — McMap. All rights reserved.