目前我在多个程序上都遇到了此错误。 我尝试过升级 pytube,重新安装它,尝试了一些修复,更改了 URL 和代码,但似乎没有任何效果。
from pytube import YouTube
#ask for the link from user
link = input("Enter the link of YouTube video you want to download: ")
yt = YouTube(link)
#Showing details
print("Title: ",yt.title)
print("Number of views: ",yt.views)
print("Length of video: ",yt.length)
print("Rating of video: ",yt.rating)
#Getting the highest resolution possible
ys = yt.streams.get_highest_resolution()
#Starting download
print("Downloading...")
ys.download()
print("Download completed!!")
这是错误代码:
File "C:\Users\Madjid\PycharmProjects\pythonProject\app2.py", line 6, in <module>
yt = YouTube(link)
File "C:\Users\Madjid\PycharmProjects\pythonProject\venv\lib\site-packages\pytube\__main__.py", line 91, in __init__
self.prefetch()
File "C:\Users\Madjid\PycharmProjects\pythonProject\venv\lib\site-packages\pytube\__main__.py", line 181, in prefetch
self.vid_info_raw = request.get(self.vid_info_url)
File "C:\Users\Madjid\PycharmProjects\pythonProject\venv\lib\site-packages\pytube\request.py", line 36, in get
return _execute_request(url).read().decode("utf-8")
File "C:\Users\Madjid\PycharmProjects\pythonProject\venv\lib\site-packages\pytube\request.py", line 24, in _execute_request
return urlopen(request) # nosec
File "E:\Python\lib\urllib\request.py", line 214, in urlopen
return opener.open(url, data, timeout)
File "E:\Python\lib\urllib\request.py", line 523, in open
response = meth(req, response)
File "E:\Python\lib\urllib\request.py", line 632, in http_response
response = self.parent.error(
File "E:\Python\lib\urllib\request.py", line 555, in error
result = self._call_chain(*args)
File "E:\Python\lib\urllib\request.py", line 494, in _call_chain
result = func(*args)
File "E:\Python\lib\urllib\request.py", line 747, in http_error_302
return self.parent.open(new, timeout=req.timeout)
File "E:\Python\lib\urllib\request.py", line 523, in open
response = meth(req, response)
File "E:\Python\lib\urllib\request.py", line 632, in http_response
response = self.parent.error(
File "E:\Python\lib\urllib\request.py", line 561, in error
return self._call_chain(*args)
File "E:\Python\lib\urllib\request.py", line 494, in _call_chain
result = func(*args)
File "E:\Python\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
尝试升级,11.0.0版本有修复:
python -m pip install --upgrade pytube
如果您还没有安装 Git,请在您的 PC 上安装: https://git-scm.com/download/win
然后以管理员身份打开命令窗口并安装此补丁:
python -m pip install git+https://github.com/Zeecka/pytube@fix_1060
我从头到尾构建了我的,并遇到了同样的问题,这里是代码和步骤。
代码:
from pytube import YouTube
from sys import argv
link = argv[1]
yt = YouTube(link)
yd = yt.streams.get_highest_resolution()
yd.download(r'C:/Users/adam/OneDrive/Desktop/video')
出现错误:
urllib.error.HTTPError: HTTP Error 410: Gone
步骤:
python -m pip install --upgrade pytube
python3 -m pip install git+https://github.com/pytube/pytube
以管理员身份运行。
效果很好!
不久前我开始了一个下载 YT 视频(MP4)的个人项目,我遇到了同样的问题以及其他问题。所有答案都有帮助,但需要 2-3 个答案组合才能解决我的问题:
首先,我必须下载 Git For Windows:(https://git-scm.com/download/win) 然后,我使用以下命令降级我已经安装的 PyTube 包。这将安装 PyTube 10.9.3:
`python -m pip install git+https://github.com/Zeecka/pytube@fix_1060`
最后,我重新安装了最新版本的 PyTube(此命令安装最新版本):
`pip install --upgrade pytube`
不确定是什么原因导致 PyTube 在首次安装时崩溃,但降级然后升级对我有用。
对于任何疑问,最终产品代码如下所示。以 720p 下载的视频,其标题为保存文件的名称。
from pytube import YouTube
#where to save
SAVE_PATH = "C:/YOUR/DESIRED/FILE/PATH/"
#link of the video to be downloaded
link = input("Enter URL >> ")
try:
yt = YouTube(link)
mp4_files = yt.streams.filter(file_extension="mp4")
mp4_720p_files = mp4_files.get_by_resolution("720p")
mp4_720p_files.download(SAVE_PATH)
except Exception as e:
print("ERROR: ", e)
来源:
HTTP 错误 410“消失”- https://www.youtube.com/watch?v=rrRuBrUrnCw
Windows 版 Git - https://git-scm.com/download/win
这是pytube版本的一个bug。您可以安装它的旧版本。将 pytube 升级到 11+ 将解决该问题。
打开终端,执行以下命令升级版本
pip install --upgrade pytube
您可以从官方GitHub仓库获取最新版本 https://github.com/pytube/pytube
python3 -m pip install git+https://github.com/pytube/pytube
我回答这个问题是因为我在互联网上找到的解决方案对我不起作用(上面的也一样)。
我什至尝试使用 GitHub 上的 ssuwani 安装其他修复程序:
pip install git+https://github.com/ssuwani/pytube
(我使用 python 3.8.10 和 Ubuntu 20.04.4 LTS)
我刚刚使用
sudo su
进入管理模式,运行我的程序并且它起作用了。说实话,我不知道为什么,但如果能有所帮助那就太好了:)
警告,当您处于管理员模式时,请勿输入任何命令,因为您可能会弄乱您的系统
我如何解决这个错误
首先使用pip卸载你的pytube
pip卸载pytube
清除点缓存
pip 缓存清除
再次安装pytube
pip 安装 pytube