首页 > 解决方案 > Pytube 错误。AttributeError:“NoneType”对象没有属性“下载”

问题描述

嗨,我正在开发一个 python youtube 下载器,这是一项非常简单的任务。我用了 pytube 一段时间,从来没有遇到过这个错误。我的代码如下:

from pytube import YouTube
import pytube
yt_title = YouTube('https://www.youtube.com/watch?v=ZjDZrReZ4EI').title
ytd = YouTube('https://www.youtube.com/watch?v=ZjDZrReZ4EI').streams.first().download()

我得到的错误消息是:

Traceback (most recent call last):
  File ".\test.py", line 5, in <module>
    ytd = YouTube('https://www.youtube.com/watch?v=ZjDZrReZ4EI').streams.first().download()
AttributeError: 'NoneType' object has no attribute 'download'

这些是电子规格:

Name: pytube
Version: 10.0.0
Summary: Python 3 library for downloading YouTube Videos.
Home-page: https://github.com/nficano/pytube
Author: Nick Ficano, Harold Martin
Author-email: nficano@gmail.com, harold.martin@gmail.com
License: MIT
Location: 'location of the package'
Requires: typing-extensions
Required-by:

我使用的视频是: https ://www.youtube.com/watch?v=ZjDZrReZ4EI

我意识到,一些我在几个小时前能够下载的视频现在无法下载

我刚刚卸载了 pytube 并安装了 pytube3。但现在我收到以下错误:

pytube.exceptions.RegexMatchError: get_ytplayer_config: could not find match 
for config_patterns

它不允许我下载任何视频。

标签: pythonpython-3.xpytube

解决方案


您必须卸载pytube并使用 pip安装pytube3 。如果它不起作用,则打印流并查看您是否正在获取流

yt = YouTube('https://www.youtube.com/watch?v=ZjDZrReZ4EI')
print(yt.streams)

推荐阅读