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


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无关,这是pytube包中的一个已知错误。

不确定你使用的是什么版本的pytube,但这个问题似乎总是在新的pytube更新后得到解决,然后在某个时候又回到了同一个问题。

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

最新更新