pytube: KeyError: 'cipher'
from pytube import YouTube
yt = YouTube('https://www.youtube.com/watch?v=3AtDnEC4zak')
---------------------------------------------------------------------------
KeyError Traceback (most recent call last)
~/.conda/envs/Karaoke/lib/python3.7/site-packages/pytube/extract.py in apply_descrambler(stream_data, key)
296 }
--> 297 for format_item in formats
298 ]
~/.conda/envs/Karaoke/lib/python3.7/site-packages/pytube/extract.py in <listcomp>(.0)
296 }
--> 297 for format_item in formats
298 ]
KeyError: 'url'
During handling of the above exception, another exception occurred:
KeyError Traceback (most recent call last)
<ipython-input-3-bc6543d387ce> in <module>
----> 1 yt = YouTube('https://www.youtube.com/watch?v=3AtDnEC4zak')
~/.conda/envs/Karaoke/lib/python3.7/site-packages/pytube/__main__.py in __init__(self, url, defer_prefetch_init, on_progress_callback, on_complete_callback, proxies)
90 if not defer_prefetch_init:
91 self.prefetch()
---> 92 self.descramble()
93
94 def descramble(self) -> None:
~/.conda/envs/Karaoke/lib/python3.7/site-packages/pytube/__main__.py in descramble(self)
130 if not self.age_restricted and fmt in self.vid_info:
131 apply_descrambler(self.vid_info, fmt)
--> 132 apply_descrambler(self.player_config_args, fmt)
133
134 if not self.js:
~/.conda/envs/Karaoke/lib/python3.7/site-packages/pytube/extract.py in apply_descrambler(stream_data, key)
299 except KeyError:
300 cipher_url = [
--> 301 parse_qs(formats[i]["cipher"]) for i, data in enumerate(formats)
302 ]
303 stream_data[key] = [
~/.conda/envs/Karaoke/lib/python3.7/site-packages/pytube/extract.py in <listcomp>(.0)
299 except KeyError:
300 cipher_url = [
--> 301 parse_qs(formats[i]["cipher"]) for i, data in enumerate(formats)
302 ]
303 stream_data[key] = [
KeyError: 'cipher'
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 14
- Comments: 54
Commits related to this issue
- Fallback to index "signatureCipher" It seems like YouTube recently changed the key name for "cipher" to "signatureCipher" and PyTube has been failing because of this. With this commit, PyTube will f... — committed to ritiek/pytube by ritiek 4 years ago
- Fallback to index "signatureCipher" It seems like YouTube recently changed the key name for "cipher" to "signatureCipher" and PyTube has been failing because of this. With this commit, PyTube will f... — committed to ritiek/pytube by ritiek 4 years ago
- Patch PyTube to correctly parse videos This code has been taken from PyTube https://github.com/nficano/pytube and is based on https://github.com/nficano/pytube/pull/643 This is because the commit re... — committed to spotDL/spotify-downloader by ritiek 4 years ago
- Patch PyTube to correctly parse videos This code has been taken from PyTube https://github.com/nficano/pytube and is based on https://github.com/nficano/pytube/pull/643 This is because the commit re... — committed to spotDL/spotify-downloader by ritiek 4 years ago
- Use a very particular, forked version of pytube See pytube issue #641 https://github.com/nficano/pytube/issues/641 — committed to c3er/ytdl by c3er 4 years ago
Yes, I have the same error and fixed it as suggested:
except KeyError: cipher_url = [ parse_qs(formats[i][“signatureCipher”]) for i, data in enumerat$ ]
When can we expect a release with the fix?
Just go to the pytube\extract.py (in pytube library)file: the path of file will be : “C:\ProgramData\Anaconda3\lib\site-packages\pytube\extract.py”, (in windows)
Open extract,py file and search for line: parse_qs(formats[i][“cipher”]) for i, data in enumerate(formats)
now replace ‘cipher’ with ‘signatureCipher’.
save it.
now run your code again
While waiting for the maintainer to address these PRs, feel free to use our public version with #643 merged in:
https://gitlab.com/obuilds/public/pytube
You can install the tagged version like so:
or add the following to your
requirements.txt
Hopefully our boy sees these MRs soon and gets a new release out.
@pranshukharkwal @Suji04 I upgraded and it worked!!!
The below code is working :
!pip install git+https://gitlab.com/obuilds/public/pytube@ob-v1 --upgrade from pytube import YouTube yt = YouTube(‘https://www.youtube.com/watch?v=-tJYN-eG1zk’)
@Suji04 @yogesh-12 Install the package from the GitLab repository shared by @kbuilds in Google Colab. Check the code below
!pip install git+https://gitlab.com/obuilds/public/pytube@ob-v1
from pytube import YouTube
yt = YouTube('https://www.youtube.com/watch?v=-tJYN-eG1zk')
`Why don’t you try the maintained fork of pytube, pytubex
extract.py line 295
Believe this is fixed in most recent version of Pytube @irahorecka @Joedmin580 @anonymous770
Let me know if this still doesnt work – thanks
Guys i figured it out:
For ’ Too Many values to unpack error:
https://github.com/nficano/pytube/pull/701/commits/773866382c3412e01f97f242e753cf32f52aaefa#diff-e5b8b42cf1afd9ee025a9e6d48697ca0
Go to this link and Replace all the data inside your cipher file with the given inside the link.It’ll work.
@Remus432 see this https://github.com/nficano/pytube/issues/695
Looks like someone is a fan of Queen