【发布时间】:2021-06-23 10:47:37
【问题描述】:
在尝试使用我制作的视频下载器时,我不断收到错误说明。 我已经查看了很多其他问题,试图找到解决方案,但几乎就像我是唯一一个遇到这个问题的人
附上错误和我的代码
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
【问题讨论】:
-
尝试打印
str(link.get())。它是正确的链接吗?YouTube(...)期待什么? -
它似乎获得了正确的链接,所以我不确定会发生什么
-
您似乎收到了 404。这意味着代码没有任何问题,您只是提供了一个无效的 URL。
标签: python python-3.x tkinter pytube