PyTube, URLlib, Http packages giving error while trying to download youtube video

dknight Source

I am trying to download youtube video using PyTube package but I am unable to do so. I am using Python 3.5 and pytube 9.2.2. Urllib doesn't give me an error in other programs but it is giving me errors here.

The code I am using is:

#importing the module
from pytube import YouTube

#where to save
SAVE_PATH = "E:/" #to_do

#link of the video to be downloaded

yt = YouTube(link)

#filters out all the files with "mp4" extension
mp4files = yt.filter('mp4')

yt.set_filename('GeeksforGeeks Video') #to set the name of the file

#get the video with the extension and resolution passed in the get() function
d_video = yt.get(mp4files[-1].extension,mp4files[-1].resolution)
    #downloading the video
    print("Some Error!")
print('Task Completed!')

The errors that I am getting are:

Traceback (most recent call last):
  File "C:\Users\hp\AppData\Local\Programs\Python\Python35\lib\urllib\", line 1240, in do_open
    h.request(req.get_method(), req.selector,, headers)
  File "C:\Users\hp\AppData\Local\Programs\Python\Python35\lib\http\", line 1083, in request
    self._send_request(method, url, body, headers)
  File "C:\Users\hp\AppData\Local\Programs\Python\Python35\lib\http\", line 1128, in _send_request
  File "C:\Users\hp\AppData\Local\Programs\Python\Python35\lib\http\", line 1079, in endheaders
  File "C:\Users\hp\AppData\Local\Programs\Python\Python35\lib\http\", line 911, in _send_output
  File "C:\Users\hp\AppData\Local\Programs\Python\Python35\lib\http\", line 854, in send
  File "C:\Users\hp\AppData\Local\Programs\Python\Python35\lib\http\", line 1237, in connect
  File "C:\Users\hp\AppData\Local\Programs\Python\Python35\lib\", line 376, in wrap_socket
  File "C:\Users\hp\AppData\Local\Programs\Python\Python35\lib\", line 747, in __init__
  File "C:\Users\hp\AppData\Local\Programs\Python\Python35\lib\", line 983, in do_handshake
  File "C:\Users\hp\AppData\Local\Programs\Python\Python35\lib\", line 628, in do_handshake
ssl.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:646)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "", line 10, in <module>
    yt = YouTube(link)
  File "C:\Users\hp\AppData\Local\Programs\Python\Python35\lib\site-packages\pytube\", line 87, in __init__
  File "C:\Users\hp\AppData\Local\Programs\Python\Python35\lib\site-packages\pytube\", line 95, in prefetch_init
  File "C:\Users\hp\AppData\Local\Programs\Python\Python35\lib\site-packages\pytube\", line 158, in prefetch
    self.watch_html = request.get(url=self.watch_url)
  File "C:\Users\hp\AppData\Local\Programs\Python\Python35\lib\site-packages\pytube\", line 21, in get
    response = urlopen(url)
  File "C:\Users\hp\AppData\Local\Programs\Python\Python35\lib\urllib\", line 162, in urlopen
    return, data, timeout)
  File "C:\Users\hp\AppData\Local\Programs\Python\Python35\lib\urllib\", line 465, in open
    response = self._open(req, data)
  File "C:\Users\hp\AppData\Local\Programs\Python\Python35\lib\urllib\", line 483, in _open
    '_open', req)
  File "C:\Users\hp\AppData\Local\Programs\Python\Python35\lib\urllib\", line 443, in _call_chain
    result = func(*args)
  File "C:\Users\hp\AppData\Local\Programs\Python\Python35\lib\urllib\", line 1283, in https_open
    context=self._context, check_hostname=self._check_hostname)
  File "C:\Users\hp\AppData\Local\Programs\Python\Python35\lib\urllib\", line 1242, in do_open
    raise URLError(err)
urllib.error.URLError: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:646)>

I wish someone could help me. PS - I am only a beginner in using urllib, http packages. Please don't write harsh comments, thank you :0



comments powered by Disqus