Python 下载 Youtube 视频时出现 Pytube 错误

Pytube Error in Python for downloading Youtube Video

我在编写使用 GUI (Tkinter ttk) 下载 YouTube 视频的程序时遇到此错误 请有人帮助我:( 我尝试了很多 Whosebug 查询,但没有任何帮助,甚至我从 Github 复制了初始代码,但错误仍然存​​在于我的系统中,但是参考人的代码是 运行 可能是它的连接错误或某事,还有一件事我有 2 chrome 扩展: 1.Touch VPN 2.Meta 面具

Exception in Tkinter callback
Traceback (most recent call last):
  File "C:\Users\lenovo\AppData\Local\Programs\Python\Python39\lib\tkinter\__init__.py", line 1892, in __call__
    return self.func(*args)
  File "f:\Sumant\Python\YouTube Downloader\yt.py", line 25, in download
    yt = YouTube(url)
  File "C:\Users\lenovo\AppData\Local\Programs\Python\Python39\lib\site-packages\pytube\__main__.py", line 91, in __init__
    self.prefetch()
  File "C:\Users\lenovo\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\lenovo\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\lenovo\AppData\Local\Programs\Python\Python39\lib\site-packages\pytube\request.py", line 24, in _execute_request
    return urlopen(request)  # nosec
  File "C:\Users\lenovo\AppData\Local\Programs\Python\Python39\lib\urllib\request.py", line 214, in urlopen
    return opener.open(url, data, timeout)
  File "C:\Users\lenovo\AppData\Local\Programs\Python\Python39\lib\urllib\request.py", line 523, in open
    response = meth(req, response)
  File "C:\Users\lenovo\AppData\Local\Programs\Python\Python39\lib\urllib\request.py", line 632, in http_response
    response = self.parent.error(
  File "C:\Users\lenovo\AppData\Local\Programs\Python\Python39\lib\urllib\request.py", line 555, in error
    result = self._call_chain(*args)
  File "C:\Users\lenovo\AppData\Local\Programs\Python\Python39\lib\urllib\request.py", line 494, in _call_chain
    result = func(*args)
  File "C:\Users\lenovo\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\lenovo\AppData\Local\Programs\Python\Python39\lib\urllib\request.py", line 523, in open
    response = meth(req, response)
  File "C:\Users\lenovo\AppData\Local\Programs\Python\Python39\lib\urllib\request.py", line 632, in http_response
    response = self.parent.error(
  File "C:\Users\lenovo\AppData\Local\Programs\Python\Python39\lib\urllib\request.py", line 561, in error
    return self._call_chain(*args)
  File "C:\Users\lenovo\AppData\Local\Programs\Python\Python39\lib\urllib\request.py", line 494, in _call_chain
    result = func(*args)
  File "C:\Users\lenovo\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 410: Gone

代码

def download():
    url = ent_link.get()
    res = var.get()

    if len(url) < 1:
        messagebox.showerror("Error", "URL cannot be Empty")
 
    yt = YouTube(url)
    try:
        if var.get() == 0:
             reso_select = yt.streams.get_highest_resolution()
        elif var.get() == 1:
            reso_select = yt.streams.get_lowest_resolution()
        elif var.get() == 2:
            reso_select = yt.streams.filter(only_audio=True).first()
        else:
            reso_select = yt.streams.get_highest_resolution()
        try:
            reso_select.download(path1)
            messagebox.showinfo("Sucess", "Video Downloaded!")
        except:
            messagebox.showerror("Error", "Download Failed")
    except:
        messagebox.showerror("Error","Please try again")

可能第 yt = YouTube(url)

行有错误

完整代码GitHub Repository

我的错误已经解决了,是pytube模块出错了 如果有人看到任何代码出现 HTTP 错误,请使用 2 个测试用例:

  1. 正确检查Link
  2. 重新安装 pytube(如果 pytube 不起作用,请安装 pytube3,但在卸载 pytube 之后)

谢谢大家!

这是 pytube 的一个错误,它以前发生过并已修复,但看起来可能 reintroduced.You 总是可以查看另一个库,例如youtube_dl 或 ytpy