Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to fix CERTIFICATE_VERIFY_FAILED? #241

Closed
KJworker opened this issue Mar 16, 2018 · 11 comments
Closed

How to fix CERTIFICATE_VERIFY_FAILED? #241

KJworker opened this issue Mar 16, 2018 · 11 comments

Comments

@KJworker
Copy link

ssl.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:777)
urllib.error.URLError: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:777)>

yt = YouTube('https://www.youtube.com/watch?v=AmIGXJ0HYHI')
video = yt.get("mp3","360p")
video.download("/Users/ken/Desktop/python_collection/youtubeCatch")

@nficano
Copy link
Collaborator

nficano commented Mar 20, 2018

this has been reported a couple times, it sounds like a local network issue, but I would love to figure out the cause and see if there's a way it can be avoided.

@nficano nficano added the bug label Mar 20, 2018
@yarodevuci
Copy link

yarodevuci commented Mar 21, 2018

@KJworker where did you get yt.get from?

'YouTube' object has no attribute 'get'

@RebelliousPebble
Copy link

If you are on a mac, running 'Install Certificates.command' from /Applications/Python3.x should fix the error. It installs a set of default Root Certificates for the python ssl module by installing the certifi https://pypi.python.org/pypi/certifi

@nombrekeff
Copy link

Referencing what @yarodevuci said:

@KJworker where did you get yt.get from?

'YouTube' object has no attribute 'get'

@apiraino
Copy link

apiraino commented Jan 8, 2019

Hello, I'm experiencing this issue, too. Strange how it appeared all of a sudden.

EDIT: I stand corrected, reporting my experience: I had a second, broken installation of OpenSSL that confused the python intepreter. Once removed the broken installation, python defaulted again to the system one - problem solved. It looks like that many instances of this error are caused by a broken OpenSSL installation.


The issue happens on this line. I did a little bit of research on this, it seems that a possible solution could be forcing the certs path using the certifi package, something along this:

diff --git a/pytube/request.py b/pytube/request.py
index 4732585..9ee0e64 100644
--- a/pytube/request.py
+++ b/pytube/request.py
@@ -1,6 +1,7 @@
 # -*- coding: utf-8 -*-
 """Implements a simple wrapper around urlopen."""
 from pytube.compat import urlopen
+import certifi
 
 
 def get(
@@ -18,7 +19,7 @@ def get(
     :param int chunk_size:
         The size in bytes of each chunk.
     """
-    response = urlopen(url)
+    response = urlopen(url, cafile=certifi.where())
     if streaming:
         return stream_response(response, chunk_size)
     elif headers:

Would such a patch make sense? I can open a PR it deemed useful

@tsor13
Copy link

tsor13 commented Feb 26, 2019

If you are on a mac, running 'Install Certificates.command' from /Applications/Python3.x should fix the error. It installs a set of default Root Certificates for the python ssl module by installing the certifi https://pypi.python.org/pypi/certifi

I had the same bug, but this solution worked perfect for me! Thank you

@github-actions
Copy link

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@jsohndata
Copy link

If you are on a mac, running 'Install Certificates.command' from /Applications/Python3.x should fix the error. It installs a set of default Root Certificates for the python ssl module by installing the certifi https://pypi.python.org/pypi/certifi

Thank you!! this resolved the issue.

Saying the same things in different way...
• Go to applications, open the Python directory, then double click on the file " Install Certifacts.command"

@binarysmurf
Copy link

If you are on a mac, running 'Install Certificates.command' from /Applications/Python3.x should fix the error. It installs a set of default Root Certificates for the python ssl module by installing the certifi https://pypi.python.org/pypi/certifi

Thank you!! this resolved the issue.

Saying the same things in different way... • Go to applications, open the Python directory, then double click on the file " Install Certifacts.command"

Not to be that guy, but this did not work for me. The 'Install Certificate' command was successful, but my SSL related errors persist.

macOS 13.1.
Python 3.10.8
Latest version of PyTube

@Reese-Sanders
Copy link

If you are on a mac, running 'Install Certificates.command' from /Applications/Python3.x should fix the error. It installs a set of default Root Certificates for the python ssl module by installing the certifi https://pypi.python.org/pypi/certifi

I had the same bug, but this solution worked perfect for me! Thank you

Works for me in 2023 as well

@data-if
Copy link

data-if commented Jan 16, 2024

If you are on a mac, running 'Install Certificates.command' from /Applications/Python3.x should fix the error. It installs a set of default Root Certificates for the python ssl module by installing the certifi https://pypi.python.org/pypi/certifi

nice

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests