Pytube: KeyError: 's'

Created on 3 May 2019  Â·  5Comments  Â·  Source: pytube/pytube

yt = Youtube('https://www.youtube.com/watch?v=dkfW1Q1T72c')
This code gives an error:

Traceback (most recent call last):
File "views.py", line 46, in
yt = YouTube(url)
File "C:\Users\Diego\AppData\Local\Programs\Python\Python37\lib\site-packages\pytube__main__.py", line 88, in __init__
self.prefetch_init()
File "C:\Users\Diego\AppData\Local\Programs\Python\Python37\lib\site-packages\pytube__main__.py", line 97, in prefetch_init
self.init()
File "C:\Users\Diego\AppData\Local\Programs\Python\Python37\lib\site-packages\pytube__main__.py", line 133, in init
mixins.apply_signature(self.player_config_args, fmt, self.js)
File "C:\Users\Diego\AppData\Local\Programs\Python\Python37\lib\site-packages\pytube\mixins.py", line 49, in apply_signature
signature = cipher.get_signature(js, stream['s'])
KeyError: 's'

This error occurs for certain URLs but not necessarily.
This problem has been bothering me for a long time, please help me solve this problem.(By the way, I am using the latest version.)
Thank you!

Most helpful comment

Quick and small workaround for ( what seems to be the most ) of the issue:
Change line 41

if ('signature=' in url):

to :

if ('signature=' in url) or ('&sig=' in url) or ('&lsig=' in url):

All 5 comments

Getting this same error, Python 2.7 and latest Pytube version. Link: https://www.youtube.com/watch?v=n25nqibaIDg

Such a problem, after downloading a few vidos it gives out. Sometimes it knocks out every 3 downloads. As luck would have it.

Quick and small workaround for ( what seems to be the most ) of the issue:
Change line 41

if ('signature=' in url):

to :

if ('signature=' in url) or ('&sig=' in url) or ('&lsig=' in url):

Quick and small workaround for ( what seems to be the most ) of the issue:
Change line 41

if ('signature=' in url):

to :

if ('signature=' in url) or ('&sig=' in url) or ('&lsig=' in url):

Perhaps this error is related to the network environment, and this error did not appear today. Thank you very much for your help, I will try your approach the next time this problem occurs. It seems that your solution has helped some people.

This video https://www.youtube.com/watch?v=cfsICOzt6Do do not download. Program failing with same error.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

NeverAskWhy picture NeverAskWhy  Â·  62Comments

Ircama picture Ircama  Â·  32Comments

SnoopiACK picture SnoopiACK  Â·  28Comments

harindu95 picture harindu95  Â·  20Comments

walpolsh picture walpolsh  Â·  44Comments