pytube: [BUG] KeyError: 'streamingData'

I’m getting KeyError: ‘streamingData’ error. I think youtube have made some changes to the data API so please fix it as soon as possible.

# Create a YouTube object and get the highest resolution stream    
      yt = YouTube(url)
      yt.register_on_progress_callback(progress_callback)
      streams = yt.streams
      # Filter streams based on type and resolution
      if resolution == "max":
        stream = streams.filter(progressive=False, type="video", file_extension="webm")
        stream = stream.order_by("resolution").desc().first()
      else:
          stream = streams.filter(progressive=False, type="video", file_extension="webm", resolution=resolution)
          stream = stream.desc().first()

Here at streams = yt.streams, I’m getting this KeyError: ‘streamingData’ Error.

About this issue

  • Original URL
  • State: open
  • Created a year ago
  • Reactions: 14
  • Comments: 16 (1 by maintainers)

Most upvoted comments

I’ve been able to determine the root cause of this error - the default client used in InnerTube class is set to ANDROID, and the response that should contain streamingData key doesn’t have it because of the error ‘Watch on the latest version of YouTube’. I believe this error appears because Android client version used in this module is outdated. I’ve fixed this issue’s error by changing to WEB client in InnerTube class, line 78: https://github.com/pytube/pytube/blob/da3141f3d937459cd7cfd9180970b9ec1d14bb5e/pytube/innertube.py#L78 Also changed this line to WEB_EMBED just to be sure: https://github.com/pytube/pytube/blob/da3141f3d937459cd7cfd9180970b9ec1d14bb5e/pytube/__main__.py#L253

@Ray_Barker solution worked for me but when I download videos now the progress callback refuses to work until the last couple percentages of the video are downloading and the videos are being downloaded at 600-700 Kbps rather than my whole bandwidth (~200 mbps). Can someone attempt to replicate this issue?