Pytube 仅定期工作(KeyError: 'assets') [英] Pytube only works periodically (KeyError: 'assets')

查看:58
本文介绍了Pytube 仅定期工作(KeyError: 'assets')的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在尝试运行我的小型测试脚本时,Pytube 十次中有五次会向我发送此错误.

Five out of ten times Pytube will send me this error when attempting to run my small testing script.

脚本如下:

import pytube
import urllib.request


from pytube import YouTube
yt = YouTube('https://www.youtube.com/watch?v=3NCyD3XoJgM')

print('Youtube video title is: ' + yt.title + '! Downloading now!')

这是我得到的:

Traceback (most recent call last):
  File "youtube.py", line 6, in <module>
    yt = YouTube('https://www.youtube.com/watch?v=3NCyD3XoJgM')
  File "C:\Users\test\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\pytube\__main__.py", line 91, in __init__
    self.prefetch()
  File "C:\Users\test\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\pytube\__main__.py", line 183, in prefetch
    self.js_url = extract.js_url(self.watch_html)
  File "C:\Users\test\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\pytube\extract.py", line 143, in js_url
    base_js = get_ytplayer_config(html)["assets"]["js"]
KeyError: 'assets'

我很困惑.我尝试重新安装 Python 和 pytube,但似乎无法解决此问题.越来越令人困惑的是,该脚本有一半时间有效,而另一半时间无效.

I am very confused. I attempted to reinstall Python plus pytube but I can't seem to remedy this issue. It's increasingly perplexing that the script works half of the time, but not the other half.

推荐答案

目前已 100% 修复:

For now fixed 100% with this:

https://github.com/nficano/pytube/pull/767#issuecomment-716184994

如果其他人收到此错误或问题,请在终端或 cmd 中运行此命令:python -m pip install git+https://github.com/nficano/pytube

With anyone else getting this error or issue, run this command in a terminal or cmd: python -m pip install git+https://github.com/nficano/pytube

尚未随 pip 安装发布的 pytubeX 更新.GitHub 链接是解释情况的当前开发人员.

An update to pytubeX that hasn't been released with the pip installation yet. The GitHub link is the current dev explaining the situation.

这篇关于Pytube 仅定期工作(KeyError: 'assets')的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆