0
from pytube import YouTube

url = input()
myvideo = YouTube(url)

print("***************Video Title****************")
# get video title
print(myvideo.title)

# set stream resolution
myvideo = myvideo.streams.get_highest_resolution()

print("Download Location")

myvideo.download()

Here's some simple code to download a video using Pytube. It works perfectly when I am using python from the terminal but just breaks when I run it on Pycharm.

The errors:

Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/urllib/request.py", line 1346, in do_open
    h.request(req.get_method(), req.selector, req.data, headers,
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/http/client.py", line 1257, in request
    self._send_request(method, url, body, headers, encode_chunked)
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/http/client.py", line 1303, in _send_request
    self.endheaders(body, encode_chunked=encode_chunked)
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/http/client.py", line 1252, in endheaders
    self._send_output(message_body, encode_chunked=encode_chunked)
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/http/client.py", line 1012, in _send_output
    self.send(msg)
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/http/client.py", line 952, in send
    self.connect()
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/http/client.py", line 1426, in connect
    self.sock = self._context.wrap_socket(self.sock,
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/ssl.py", line 500, in wrap_socket
    return self.sslsocket_class._create(
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/ssl.py", line 1040, in _create
    self.do_handshake()
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/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:1129)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/danielgao/PycharmProjects/pythonProject/ytdownloader.py", line 9, in <module>
    print(myvideo.title)
  File "/Users/danielgao/PycharmProjects/pythonProject/venv/lib/python3.9/site-packages/pytube/__main__.py", line 337, in title
    self._title = self.vid_info['videoDetails']['title']
  File "/Users/danielgao/PycharmProjects/pythonProject/venv/lib/python3.9/site-packages/pytube/__main__.py", line 242, in vid_info
    innertube_response = innertube.player(self.video_id)
  File "/Users/danielgao/PycharmProjects/pythonProject/venv/lib/python3.9/site-packages/pytube/innertube.py", line 300, in player
    return self._call_api(endpoint, query, self.base_data)
  File "/Users/danielgao/PycharmProjects/pythonProject/venv/lib/python3.9/site-packages/pytube/innertube.py", line 242, in _call_api
    response = request._execute_request(
  File "/Users/danielgao/PycharmProjects/pythonProject/venv/lib/python3.9/site-packages/pytube/request.py", line 37, in _execute_request
    return urlopen(request, timeout=timeout)  # nosec
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/urllib/request.py", line 214, in urlopen
    return opener.open(url, data, timeout)
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/urllib/request.py", line 517, in open
    response = self._open(req, data)
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/urllib/request.py", line 534, in _open
    result = self._call_chain(self.handle_open, protocol, protocol +
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/urllib/request.py", line 494, in _call_chain
    result = func(*args)
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/urllib/request.py", line 1389, in https_open
    return self.do_open(http.client.HTTPSConnection, req,
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/urllib/request.py", line 1349, 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:1129)>
OneCricketeer
  • 179,855
  • 19
  • 132
  • 245
dg__
  • 1
  • Welcome to Stack Overflow. I have fixed your formatting (error tracebacks should be formatted like code) and removed some [noise](https://meta.stackoverflow.com/questions/343721/kind-reminder-to-remove-noise) from your question - we don't care about your level of experience, and there isn't yet a reason to suspect that your platform matters here (this isn't tech support, so questions where that matters are less likely to be on topic). – Karl Knechtel Oct 04 '21 at 22:34
  • How about [SSL: CERTIFICATE_VERIFY_FAILED with Python3](https://stackoverflow.com/q/35569042/3890632) – khelwood Oct 04 '21 at 22:36
  • That said, we need more from you to have an answerable Stack Overflow question. In particular: what do you mean by "run it on Pytube"? Also, what is your actual *question*? Please see [ask] and https://meta.stackoverflow.com/questions/284236/ - we cannot just give you "some help with this". You should start by trying to do some [research](https://meta.stackoverflow.com/questions/261592/) - for example, what if you copy and paste the error message at the end into a search engine? – Karl Knechtel Oct 04 '21 at 22:36
  • Sounds to me like your terminal Python is not the same version as Pycharm's interpreter (show `python -V`) – OneCricketeer Oct 04 '21 at 22:39

0 Answers0