get-pytube / pytube3

A lightweight, dependency-free Python 3 library (and command-line utility) for downloading YouTube Videos.
https://pytube3.readthedocs.io
Other
178 stars 55 forks source link

SSL: CERTIFICATE_VERIFY_FAILED #78

Closed WyattBlue closed 1 year ago

WyattBlue commented 4 years ago

Running

>>> from pytube import YouTube
>>> YouTube('https://youtu.be/9bZkp7q19f0').streams.get_highest_resolution().download()

gives this error

Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/urllib/request.py", line 1319, in do_open
    h.request(req.get_method(), req.selector, req.data, headers,
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/http/client.py", line 1230, in request
    self._send_request(method, url, body, headers, encode_chunked)
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/http/client.py", line 1276, in _send_request
    self.endheaders(body, encode_chunked=encode_chunked)
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/http/client.py", line 1225, in endheaders
    self._send_output(message_body, encode_chunked=encode_chunked)
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/http/client.py", line 1004, in _send_output
    self.send(msg)
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/http/client.py", line 944, in send
    self.connect()
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/http/client.py", line 1399, in connect
    self.sock = self._context.wrap_socket(self.sock,
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/ssl.py", line 500, in wrap_socket
    return self.sslsocket_class._create(
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/ssl.py", line 1040, in _create
    self.do_handshake()
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/ssl.py", line 1309, in do_handshake
    self._sslobj.do_handshake()
ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1108)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pytube/__main__.py", line 91, in __init__
    self.prefetch()
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pytube/__main__.py", line 162, in prefetch
    self.watch_html = request.get(url=self.watch_url)
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pytube/request.py", line 36, in get
    return _execute_request(url).read().decode("utf-8")
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pytube/request.py", line 24, in _execute_request
    return urlopen(request)  # nosec
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/urllib/request.py", line 222, in urlopen
    return opener.open(url, data, timeout)
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/urllib/request.py", line 525, in open
    response = self._open(req, data)
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/urllib/request.py", line 542, in _open
    result = self._call_chain(self.handle_open, protocol, protocol +
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/urllib/request.py", line 502, in _call_chain
    result = func(*args)
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/urllib/request.py", line 1362, in https_open
    return self.do_open(http.client.HTTPSConnection, req,
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/urllib/request.py", line 1322, in do_open
    raise URLError(err)
urllib.error.URLError: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1108)>

any ideas how to fix it?

mattmovesmountains commented 3 years ago

Hi Wyatt, did you ever figure this one out? I just ran into the same thing right now. My code is similar in the sense that I'm downloading with pytube, and the difference in output is that it runs fine on my own computer, but it's generating this same error when my friend tries to run it on her mac from an executable that I made.

WyattBlue commented 3 years ago

@mattmovesmountains No, I switched to using youtube-dl pip library.

mattmovesmountains commented 3 years ago

Good to know - thank you!

On Thu, Apr 22, 2021, 4:15 PM WyattBlue @.***> wrote:

@mattmovesmountains https://github.com/mattmovesmountains No, I switched to using youtube-dl pip library.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/get-pytube/pytube3/issues/78#issuecomment-825155268, or unsubscribe https://github.com/notifications/unsubscribe-auth/ASUYQULNGY5JXOSY722CJH3TKB7XPANCNFSM4NC64MVQ .

WyattBlue commented 1 year ago

Use yt-dlp instead of pytube.