Five out of ten times Pytube will send me this error when attempting to run my small testing script.
Here's the 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!')
Here's what I get:
Traceback (most recent call last):
File "youtube.py", line 6, in <module>
yt = YouTube('https://www.youtube.com/watch?v=3NCyD3XoJgM')
File "C:UsersestAppDataLocalPackagesPythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0LocalCachelocal-packagesPython38site-packagespytube\__main__.py", line 91, in __init__
self.prefetch()
File "C:UsersestAppDataLocalPackagesPythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0LocalCachelocal-packagesPython38site-packagespytube\__main__.py", line 183, in prefetch
self.js_url = extract.js_url(self.watch_html)
File "C:UsersestAppDataLocalPackagesPythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0LocalCachelocal-packagesPython38site-packagespytubeextract.py", line 143, in js_url
base_js = get_ytplayer_config(html)["assets"]["js"]
KeyError: 'assets'
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.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…