尝试使用 pytube 时 Tkinter 回调中的异常

Exception in Tkinter callback when trying to use pytube

尝试使用我制作的视频下载器时,我不断收到这样的错误提示。 我已经看了很多其他问题试图找到解决方案,但几乎就像我是唯一遇到这个问题的人

附上错误和我的代码

   import pytube
   import tkinter
   from tkinter import *
   from pytube import YouTube
   
   root = Tk()
   root.geometry('500x300')
   root.resizable(0,0)
   root.title("DataFlair-youtube video downloader")
   
   
   Label(root,text = 'Youtube Video Downloader', font ='arial 20 bold').pack()
   
   link = StringVar()
   
   Label(root, text = 'Paste Link Here:', font = 'arial 15 bold').place(x= 160 , y = 60)
   link_enter = Entry(root, width = 70,textvariable = link).place(x = 32, y = 90)
   
   
   def Downloader():
        
       url =YouTube(str(link.get()))
       video = url.streams.first()
       video.download()
       Label(root, text = 'DOWNLOADED', font = 'arial 15').place(x= 180 , y = 210)  
   
   
   Button(root,text = 'DOWNLOAD', font = 'arial 15 bold' ,bg = 'pale violet red', padx = 2, command = Downloader).place(x=180 ,y = 150)
   
   
   
   root.mainloop()

    Exception in Tkinter callback Traceback (most recent call last):   File "C:\Users\Owner\AppData\Local\Programs\Python\Python39\lib\tkinter\__init__.py", line 1884, in __call__
        return self.func(*args)   File "c:\Users\Owner\Downloads\youtube_download.py", line 22, in Downloader
        url =YouTube(str(link.get()))   File "C:\Users\Owner\AppData\Local\Programs\Python\Python39\lib\site-packages\pytube\__main__.py", line 91, in __init__
        self.prefetch()   File "C:\Users\Owner\AppData\Local\Programs\Python\Python39\lib\site-packages\pytube\__main__.py", line 181, in prefetch
        self.vid_info_raw = request.get(self.vid_info_url)   File "C:\Users\Owner\AppData\Local\Programs\Python\Python39\lib\site-packages\pytube\request.py", line 36, in get
        return _execute_request(url).read().decode("utf-8")   File "C:\Users\Owner\AppData\Local\Programs\Python\Python39\lib\site-packages\pytube\request.py", line 24, in _execute_request
        return urlopen(request)  # nosec   File "C:\Users\Owner\AppData\Local\Programs\Python\Python39\lib\urllib\request.py", line 214, in urlopen
        return opener.open(url, data, timeout)   File "C:\Users\Owner\AppData\Local\Programs\Python\Python39\lib\urllib\request.py", line 523, in open
        response = meth(req, response)   File "C:\Users\Owner\AppData\Local\Programs\Python\Python39\lib\urllib\request.py", line 632, in http_response
        response = self.parent.error(   File "C:\Users\Owner\AppData\Local\Programs\Python\Python39\lib\urllib\request.py", line 555, in error
        result = self._call_chain(*args)   File "C:\Users\Owner\AppData\Local\Programs\Python\Python39\lib\urllib\request.py", line 494, in _call_chain
        result = func(*args)   File "C:\Users\Owner\AppData\Local\Programs\Python\Python39\lib\urllib\request.py", line 747, in http_error_302
        return self.parent.open(new, timeout=req.timeout)   File "C:\Users\Owner\AppData\Local\Programs\Python\Python39\lib\urllib\request.py", line 523, in open
        response = meth(req, response)   File "C:\Users\Owner\AppData\Local\Programs\Python\Python39\lib\urllib\request.py", line 632, in http_response
        response = self.parent.error(   File "C:\Users\Owner\AppData\Local\Programs\Python\Python39\lib\urllib\request.py", line 561, in error
        return self._call_chain(*args)   File "C:\Users\Owner\AppData\Local\Programs\Python\Python39\lib\urllib\request.py", line 494, in _call_chain
        result = func(*args)   File "C:\Users\Owner\AppData\Local\Programs\Python\Python39\lib\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

当我使用 Pytube 10.8.3 运行 时出现错误 404 但它适用于最新的 10.8.5

只是 YouTube 有时会在页面上进行更改,PyTube 可能也需要更新。

其他人也遇到过与 pytube 相同的问题。您可能想在此处查看解决方案。