Search code examples
tk-toolkitpytube

I'm getting HTTP error 404 making this code to download YouTube any idea as to why I'm pretty sure there's nothing wrong with the links tried loads


import ssl
ssl._create_default_https_context = ssl._create_unverified_context
from tkinter import *
from pytube import *
##just a title
root =Tk()
root.title('Youtube Downloader')


##label at the top of 
ytdLabel= Label(root,text='Enter URL of the video',font=('jost',15))
ytdLabel.pack()

##entry bar
enterURL=Entry(root,width=30)
enterURL.pack()

##
def URLDownloader():
    myvid=(str(enterURL.get()))
    video=YouTube(myvid)
    video=video.streams.get_highest_resolution()
    video.download()
   
dwnloadBtn=Button(root,text='Download',command=URLDownloader)
dwnloadBtn.pack()

root.mainloop()

Exception in Tkinter callback

Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/tkinter/__init__.py", line 1892, in __call__
    return self.func(*args)
  File "/Users/jordanshodeinde/Desktop/Youtube downloader progression/youtube dowloader.py", line 25, in URLDownloader
    video=YouTube(myvid)
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/pytube/__main__.py", line 91, in __init__
    self.prefetch()
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/pytube/__main__.py", line 181, in prefetch
    self.vid_info_raw = request.get(self.vid_info_url)
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/pytube/request.py", line 36, in get
    return _execute_request(url).read().decode("utf-8")
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/pytube/request.py", line 24, in _execute_request
    return urlopen(request)  # 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 523, in open
    response = meth(req, response)
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/urllib/request.py", line 632, in http_response
    response = self.parent.error(
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/urllib/request.py", line 555, in error
    result = self._call_chain(*args)
  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 747, in http_error_302
    return self.parent.open(new, timeout=req.timeout)
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/urllib/request.py", line 523, in open
    response = meth(req, response)
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/urllib/request.py", line 632, in http_response
    response = self.parent.error(
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/urllib/request.py", line 561, in error
    return self._call_chain(*args)
  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 641, in http_error_default
    raise HTTPError(req.full_url, code, msg, hdrs, fp)
urllib.error.HTTPError: HTTP Error 404: Not Found

Solution

  • The problem for this error has nothing to do with Tkinter, this is a known bug with the pytube package.

    Not sure what version of pytube you're using but this issue always seems to be solved after a new pytube update then it goes back to the same issue sometime down the line.

    But you can try pip install pytube==10.9.2 as this is now the latest version or python -m pip install --upgrade pytube. Hopefully that will resolve the issue you're now facing.