我收到 HTTP 错误 404 使此代码下载 YouTube 任何关于为什么我很确定尝试加载的链接没有问题的想法

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()

Tkinter 回调异常

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

此错误的问题与 Tkinter 无关,这是一个 known bug 与 pytube 包有关的问题。

不确定您使用的是哪个版本的 pytube,但这个问题似乎总是在新的 pytube 更新后得到解决,然后它会在某个时候回到相同的问题。

但您可以尝试 pip install pytube==10.9.2,因为这是现在的最新版本或 python -m pip install --upgrade pytube。希望这将解决您现在面临的问题。