question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Key Error of 'Assets' when attempting to call 'YouTube()'

See original GitHub issue

When doing the following command:

from pytube import YouTube
yt = YouTube('http://youtube.com/watch?v=9bZkp7q19f0')

I’m seeing the key error ‘assets’:

KeyError Traceback (most recent call last) <ipython-input-2-4ab0b1497744> in <module> ----> 1 yt = YouTube(‘http://youtube.com/watch?v=9bZkp7q19f0’)

C:\Program Files\Anaconda3\lib\site-packages\pytube_main_.py in init(self, url, defer_prefetch_init, on_progress_callback, on_complete_callback, proxies) 89 90 if not defer_prefetch_init: —> 91 self.prefetch() 92 self.descramble() 93

C:\Program Files\Anaconda3\lib\site-packages\pytube_main_.py in prefetch(self) 181 self.vid_info_raw = request.get(self.vid_info_url) 182 if not self.age_restricted: –> 183 self.js_url = extract.js_url(self.watch_html) 184 self.js = request.get(self.js_url) 185

C:\Program Files\Anaconda3\lib\site-packages\pytube\extract.py in js_url(html) 141 The html contents of the watch page. 142 “”" –> 143 base_js = get_ytplayer_config(html)[“assets”][“js”] 144 return “https://youtube.com” + base_js 145

KeyError: ‘assets’

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:14

github_iconTop GitHub Comments

5reactions
AssesBessescommented, Oct 27, 2020

Hi, Since yesterday I have the same, on every version of pytube (pytube, pytube3, pytubex). I thought youtube banned my ip address because I downloaded almost 300GB yesterday and it suddenly stopped working. It looks like youtube changed something yesterday which made pytube not working at all.

I found a problem. I don’t know regex, so my solution is primitive but works fully. There is a js_url() function in the extract.py file. Delete it completely (or rename it). Create a new js_url() function, it should look like this:

def js_url(html: str) -> str: start = html.find('src="/s/player/') +5 stop = html[start:].find('base.js') + 7 js_url = html[start:start + stop] return "https://youtube.com" + js_url

Doesn’t work with age-restricted videos, but now I know why, I’ll post a revised code tomorrow. Today I downloaded over 500 videos without any errors.

4reactions
tfdahlincommented, Oct 27, 2020

@vincehartman38 @AssesBesses this problem was fixed in the most recent update to the repository, so you will need to reinstall pytube in order to fix it.

To install from this repository, I recommend you first uninstall pytube with pip uninstall pytube, then re-install it with python -m pip install git+https://github.com/nficano/pytube.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Key Error of 'Assets' when attempting to call 'YouTube()' #777
I found a problem. I don't know regex, so my solution is primitive but works fully. There is a js_url() function in the...
Read more >
Pytube only works periodically (KeyError: 'assets')
Here's the script: import pytube import urllib.request from pytube import YouTube yt = YouTube('https://www.
Read more >
YouTube Data API - Errors | Google Developers
The following tables identify error messages that the API returns in response to calls related to activities resources.
Read more >
Handling the "Unable to Find the Object" Error - Part One
Learn how TestComplete finds objects over which it simulates user actions when it does not use Name Mapping and how to fix the...
Read more >
How to fix Unexpected Token in JSON error (for ... - YouTube
If you get this error in an app you didn't make, and/or you're not a web developer... this video will not help you....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found