【发布时间】:2021-08-08 15:39:54
【问题描述】:
我在制作使用 GUI (Tkinter ttk) 下载 YouTube 视频的程序时遇到此错误 请有人帮助我:( 我尝试了很多 stackoverflow 查询,但没有任何帮助,甚至我从 Github 复制了初始代码,但错误仍然存在于我的系统中,但是代码在参考人处正常运行 也许是它的连接错误或者我有 2 个 chrome 扩展的东西: 1.触摸VPN 2.元掩码
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)行有错误
【问题讨论】:
-
“HTTP 错误 410:已消失”表示该资源已从其服务器中删除。除非他们发送这个来搞乱抓取工具,否则这意味着这不是您的代码的问题。您正在尝试获取一个不再存在的视频。
-
这也不是
RuntimeError。这是一个urllib.error.HTTPError。所以请删除问题上的runtime-error标签。 -
另外,不要使用
except:。这似乎不是你现在的问题,但是像这样的裸except案例会在某个时候咬你。始终指定要捕获的异常。 -
@Carcigenicate youtube.com/watch?v=Lynx3vZz5Ao&t=1s 有结帐视频,您可以使用 GitHub 链接并使用代码从 YT 下载任何东西
-
该代码在使用 pytube 11.0.0 和 Python 3.8.10 的 youtube 链接上运行良好。
标签: python tkinter urllib pytube