[GH-ISSUE #532] Invalid context URI and bad request for URL error 400 #320

Closed
opened 2026-02-27 23:21:59 +03:00 by kerem · 2 comments
Owner

Originally created by @Esamanoaz on GitHub (Jul 7, 2020).
Original GitHub issue: https://github.com/spotipy-dev/spotipy/issues/532

Describe the bug
When trying to play just one song to a Chromecast device, I get the below errors. If I pass in a list of the same song at least twice, the program runs without errors and the list of songs is played on my speaker.

My code
The entire code
Just the context needed
The smallest context possible:
# Start playback
if args.uri[0].find("track") > 0:
client.start_playback(device_id=spotify_device_id, uris=args.uri)
else:
client.start_playback(device_id=spotify_device_id, context_uri=args.uri[0])

Expected behavior
The above if/else statement should go to else because only one URI is being passed in. Then, my Google Home Mini speaker should start playing that song.

Output
Error output with device id replaced as "my_device_id_here"

Environment:

  • OS: Windows 10
  • Python version: 3.8.1
  • spotipy version: 2.13
  • IDE: Visual Studio Code

Additional context
I am using spotipy, spotify-token, and pychromecast to play music from Spotify on my Google Home Mini. The album or song URI's will be stored on NFC tags with the album cover art printed on them. Here is an example on credit, where the OP used Spotify and Sonos. I am recreating their project with casting to a Google Home speaker.

Originally created by @Esamanoaz on GitHub (Jul 7, 2020). Original GitHub issue: https://github.com/spotipy-dev/spotipy/issues/532 **Describe the bug** When trying to play just one song to a Chromecast device, I get the below errors. If I pass in a list of the same song at least twice, the program runs without errors and the list of songs is played on my speaker. **My code** [The entire code](https://pastebin.com/H2MkVVSP) [Just the context needed](https://pastebin.com/y3cCNe1a) The smallest context possible: `# Start playback` `if args.uri[0].find("track") > 0:` ` client.start_playback(device_id=spotify_device_id, uris=args.uri)` `else:` ` client.start_playback(device_id=spotify_device_id, context_uri=args.uri[0])` **Expected behavior** The above if/else statement should go to else because only one URI is being passed in. Then, my Google Home Mini speaker should start playing that song. **Output** [Error output with device id replaced as "my_device_id_here"](https://pastebin.com/PnfZ6R9f) **Environment:** - OS: Windows 10 - Python version: 3.8.1 - spotipy version: 2.13 - IDE: Visual Studio Code **Additional context** I am using spotipy, spotify-token, and pychromecast to play music from Spotify on my Google Home Mini. The album or song URI's will be stored on NFC tags with the album cover art printed on them. [Here](https://www.reddit.com/r/Python/comments/he081v/i_wrote_a_python_script_to_play_an_album_on_sonos/) is an example on credit, where the OP used Spotify and Sonos. I am recreating their project with casting to a Google Home speaker.
kerem 2026-02-27 23:21:59 +03:00
  • closed this issue
  • added the
    bug
    label
Author
Owner

@stephanebruckert commented on GitHub (Jul 12, 2020):

If bug appears on this line, please print what args.uri exactly equals to. uris expects a list of track uris

client.start_playback(device_id=spotify_device_id, uris=args.uri)

And if bug appears on this line, please print what args.uri[0] exactly equals to. context_uri should be a string representing a uri

client.start_playback(device_id=spotify_device_id, context_uri=args.uri[0])

https://spotipy.readthedocs.io/en/2.13.0/#spotipy.client.Spotify.start_playback

<!-- gh-comment-id:657278172 --> @stephanebruckert commented on GitHub (Jul 12, 2020): If bug appears on this line, please print what `args.uri` exactly equals to. `uris` expects a list of track uris > client.start_playback(device_id=spotify_device_id, uris=args.uri) And if bug appears on this line, please print what `args.uri[0]` exactly equals to. `context_uri` should be a string representing a uri > client.start_playback(device_id=spotify_device_id, context_uri=args.uri[0]) https://spotipy.readthedocs.io/en/2.13.0/#spotipy.client.Spotify.start_playback
Author
Owner

@Esamanoaz commented on GitHub (Jul 12, 2020):

Nevermind, I misunderstood the parameters.

I was passing in a string containing one URI into uris. What I needed to do was pass in a list instead of a string. My bad.

<!-- gh-comment-id:657288249 --> @Esamanoaz commented on GitHub (Jul 12, 2020): Nevermind, I misunderstood the parameters. I was passing in a string containing one URI into uris. What I needed to do was pass in a list instead of a string. My bad.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/spotipy#320
No description provided.