pytube: KeyError: 'streamingData'

I was trying to download https://www.youtube.com/watch?v=NdA778dQrXE

And this always raises KeyError: ‘streamingData’ error.

>>> YouTube("https://www.youtube.com/watch?v=NdA778dQrXE")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\LENOVO\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pytube\__main__.py", line 92, in __init__
    self.descramble()
  File "C:\Users\LENOVO\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pytube\__main__.py", line 132, in descramble
    apply_descrambler(self.player_config_args, fmt)
  File "C:\Users\LENOVO\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pytube\extract.py", line 281, in apply_descrambler
    formats = json.loads(stream_data["player_response"])["streamingData"]["formats"]
KeyError: 'streamingData'

List of some videos raises the same error.

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 5
  • Comments: 73

Most upvoted comments

If you install both pytube3 and pytube with pip, certain files get overwritten in unintended ways. This is especially true because the pypi packages haven’t been updated in several months.

You should be able to fix this problem if you do the following:

  1. Run pip uninstall pytube
  2. Run pip uninstall pytube3
  3. Run python -m pip install git+https://github.com/nficano/pytube

This should uninstall the conflicting versions of pytube, and install the most recent code from this repository.

First locate pytube library location

Screenshot 2023-04-28 195628

Click on “innertube.py” and edit the code on line 78 replacing client=‘ANDROID’ with client=‘WEB’

image

It worked pretty well for me but the problem is downloading video or audio is slow

Apparently the view I’m trying to download is age restricted

https://www.youtube.com/watch?v=v4HkASndEXo

The error is not intuitive.

Same issue here, error appears to occur with age restricted videos…

why is this closed? It is still not working

I finally got a solution for this KeyError: ‘Streaming Data’. This error arises if you are trying to download videos that require a sign in / login for example Age Restricted videos require sign in or login. I tried to keep an exception for Age Restricted from pytube.exceptions but the error still persists because the statement for exception didn’t actually run for some reason. Actually this is not even an error but a bug.

Solution I included several exception in below example i am trying to download the Youtube 8m dataset.

    for video_id in video_id_list:
        try:
            YouTube('http://youtube.com/watch?v=' + video_id).streams.get_highest_resolution().download(vedio_dir)
        except (VideoUnavailable, HTTPError, ConnectionError,RemoteDisconnected, ConnectTimeout, InvalidURL, ProtocolError, AgeRestrictedError, VideoRegionBlocked, LiveStreamError, RecordingUnavailable, MembersOnly, VideoPrivate, Exception):
            try:
                YouTube('http://youtube.com/watch?v=' + video_id).streams.get_highest_resolution().download(vedio_dir)
            except (VideoUnavailable, HTTPError, ConnectionError,RemoteDisconnected, ConnectTimeout, InvalidURL, ProtocolError, AgeRestrictedError, VideoRegionBlocked, LiveStreamError, RecordingUnavailable, MembersOnly, VideoPrivate, Exception):
                print(' http://youtube.com/watch?v=' + video_id)

This made me download those videos without problem. Kindly try even if my solution looks silly.

Same issue here. There’s a way to make it work, but much slower: https://github.com/pytube/pytube/issues/743#issuecomment-1528453973 (I tried it and it’s working)

I solved the problem in linux as follows:

sudo gedit  /usr/local/lib/python3.8/dist-packages/pytube/innertube.py

Wait…

Change the line:

class InnerTube:
    """Object for interacting with the innertube API."""
    def __init__(self, client='ANDROID', use_oauth=False, allow_cache=True):
        """Initialize an InnerTube object.

        :param str client:
            Client to use for the object.
            Default to web because it returns the most playback types.
        :param bool use_oauth:
            Whether or not to authenticate to YouTube.
        :param bool allow_cache:
            Allows caching of oauth tokens on the machine.
        """
        self.context = _default_clients[client]['context']
        self.api_key = _default_clients[client]['api_key']
        self.access_token = None
        self.refresh_token = None
        self.use_oauth = use_oauth
        self.allow_cache = allow_cache

for

class InnerTube:
    """Object for interacting with the innertube API."""
    def __init__(self, client='WEB', use_oauth=False, allow_cache=True):
        """Initialize an InnerTube object.

        :param str client:
            Client to use for the object.
            Default to web because it returns the most playback types.
        :param bool use_oauth:
            Whether or not to authenticate to YouTube.
        :param bool allow_cache:
            Allows caching of oauth tokens on the machine.
        """
        self.context = _default_clients[client]['context']
        self.api_key = _default_clients[client]['api_key']
        self.access_token = None
        self.refresh_token = None
        self.use_oauth = use_oauth
        self.allow_cache = allow_cache

line 78 Only change the client from Android to WEB, probably the problem only occurs for android due to an update.

Hello, Recently I got into the same issue. Solved it by setting the variable transform_plan_raw in cipher.py to js. So go to {home}/.local/lib/{your_pythonversion: ex. python3.10}/site-packages/pytube/cipher.py Line 411 and replace the value of thetransform_plan_raw variable as follows: transform_plan_raw = js #find_object_from_startpoint(raw_code, match.span()[1] - 1)

Tried this in google colab. It doesn’t work even after runtime restart. Curious why did you try this? @anabild

Hello,

Got it from https://github.com/pytube/pytube/commit/d6623d8ce39c777f22a5638307c9fceedc01b047 I am using a virtual env and a VM with Linux and it just worked for me 😃

I´m having the same issue. Any thoughts?

Apparently, everyone started getting that error. Me as well, I just switched to yt-dlp (https://github.com/yt-dlp/yt-dlp) and it works perfectly now

The package was working fine, but suddenly stopped working.

$ python download_youtube.py
Traceback (most recent call last):
  File "/home/kali/download_youtube.py", line 7, in <module>
    stream = yt.streams.get_highest_resolution()
             ^^^^^^^^^^
  File "/home/kali/.local/lib/python3.11/site-packages/pytube/__main__.py", line 296, in streams
    return StreamQuery(self.fmt_streams)
                       ^^^^^^^^^^^^^^^^
  File "/home/kali/.local/lib/python3.11/site-packages/pytube/__main__.py", line 176, in fmt_streams
    stream_manifest = extract.apply_descrambler(self.streaming_data)
                                                ^^^^^^^^^^^^^^^^^^^
  File "/home/kali/.local/lib/python3.11/site-packages/pytube/__main__.py", line 161, in streaming_data

    return self.vid_info['streamingData']
           ~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^
KeyError: 'streamingData'

My situation is using pytube 12.1.3, and downloading a public vedio got such error, the root cause is playability_status method return an array with 1 element in it: None, so we need to change the lib line 213, adding the condition of None:

   def check_availability(self):
        """Check whether the video is available.

        Raises different exceptions based on why the video is unavailable,
        otherwise does nothing.
        """
        status, messages = extract.playability_status(self.watch_html)

        for reason in messages:
            if status is None:
                pass

Same issue here : windows 11 pytube 12.1.3 python 3.10

First locate pytube library location

Screenshot 2023-04-28 195628

Click on “innertube.py” and edit the code on line 78 replacing client=‘ANDROID’ with client=‘WEB’

image

It worked pretty well for me but the problem is downloading video or audio is slow

Thanks for this. This fixed the issue! by changing the innertube.py from ANDROID to WEB it seems to go much slower. Is their any fix for that?

Thanks a ton!

Shouldn’t close it that fast. March 2022, and the problem is still there. version 12