Skip to content

Fix YouTube casting by adding Content-Length header#1155

Open
andrew-kurin wants to merge 1 commit intohome-assistant-libs:masterfrom
andrew-kurin:fix-youtube-content-length-header
Open

Fix YouTube casting by adding Content-Length header#1155
andrew-kurin wants to merge 1 commit intohome-assistant-libs:masterfrom
andrew-kurin:fix-youtube-content-length-header

Conversation

@andrew-kurin
Copy link
Copy Markdown

Problem

YouTube casting via YouTubeController fails with HTTP 400 error:

requests.exceptions.HTTPError: 400 Client Error: Parameter missing. 
for url: https://www.youtube.com/api/lounge/pairing/get_lounge_token_batch

This affects tools like catt that use pychromecast for YouTube casting.

Root Cause

YouTube's lounge API now requires the Content-Length header on POST requests. This is a recent change on YouTube's side.

Prior Art

This issue was first identified in the upstream casttube library:

Since pychromecast's TimeoutYouTubeSession class overrides the _do_post() method from casttube, the fix needs to be applied here as well.

Fix

  1. Copy the HEADERS dict instead of referencing it directly (to avoid mutating the shared constant)
  2. Calculate and add Content-Length header for dict POST data using urllib.parse.urlencode()

Testing

Tested with catt v0.13.1 casting YouTube videos to Google Nest Hub - works after applying this fix.

Notes

The casttube maintainer appears inactive (PR open for 2+ years), so this fix in pychromecast is necessary for the ecosystem to work properly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant