pycharm 属性错误:使用pytube时,“NoneType”对象没有属性“span”

mw3dktmi  于 2023-03-18  发布在  PyCharm
关注(0)|答案(1)|浏览(296)

我有一个问题时,从pytube模块下载视频,我尝试更新pytube,再次下载,仍然不工作,我使用的是python 3.11,这是我的代码:
'定义进程函数(流,块,剩余字节):打印(“下载”)def完成函数(流,文件路径):print(“下载完成”)messagebox.showinfo(title=“下载完成”,message=“视频下载成功”)
def下载():用户输入=字符串(链接.get())yt = YouTube(用户输入,进度回调=进度函数,完成回调=完成函数)打印(yt.标题)打印(yt.缩略图url)视频= yt.流.get_highest_resolution()video.download()'
这就是错误所在:
Exception in Tkinter callback Traceback (most recent call last): File "C:\Users\---\AppData\Local\Programs\Python\Python311\Lib\tkinter\__init__.py", line 1948, in __call__ return self.func(*args) ^^^^^^^^^^^^^^^^ File "C:\Users\---\PycharmProjects\youtube downloader\main.py", line 30, in download video = yt.streams.get_highest_resolution() ^^^^^^^^^^ File "C:\Users\---\PycharmProjects\youtube downloader\venv\day\QuizGame\Lib\site-packages\pytube\__main__.py", line 296, in streams return StreamQuery(self.fmt_streams) ^^^^^^^^^^^^^^^^ File "C:\Users\---\PycharmProjects\youtube downloader\venv\day\QuizGame\Lib\site-packages\pytube\__main__.py", line 181, in fmt_streams extract.apply_signature(stream_manifest, self.vid_info, self.js) File "C:\Users\---\PycharmProjects\youtube downloader\venv\day\QuizGame\Lib\site-packages\pytube\extract.py", line 409, in apply_signature cipher = Cipher(js=js) ^^^^^^^^^^^^^ File "C:\Users\---\PycharmProjects\youtube downloader\venv\day\QuizGame\Lib\site-packages\pytube\cipher.py", line 29, in __init__ self.throttling_plan = get_throttling_plan(js) ^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\---\PycharmProjects\youtube downloader\venv\day\QuizGame\Lib\site-packages\pytube\cipher.py", line 404, in get_throttling_plan transform_plan_raw = find_object_from_startpoint(raw_code, match.span()[1] - 1) ^^^^^^^^^^ AttributeError: 'NoneType' object has no attribute 'span'使用pytube下载youtube视频。

yqkkidmi

yqkkidmi1#

这是pytube库中的一个错误。这是由于YouTube对其JavaScript代码进行了一些更改而导致的。要修复它,请查看pytube Github中的此建议。
进入你的pytube库文件夹,找到cipher.py文件,修改第411行:

transform_plan_raw = find_object_from_startpoint(raw_code, match.span()[1] - 1)

该正则表达式是引发错误的正则表达式,请改为:

transform_plan_raw = js

最终pytube将发布更新并修复此错误。

相关问题