[GH-ISSUE #1082] Unable To Start Playback #640

Closed
opened 2026-02-28 00:00:28 +03:00 by kerem · 2 comments
Owner

Originally created by @ZacharyBrammer on GitHub (Mar 31, 2024).
Original GitHub issue: https://github.com/spotipy-dev/spotipy/issues/1082

Hey y'all, just started using spotipy and I'm having issues getting playback to start. I'm trying to control music playing on my laptop (or whatever device) from a raspberry pi.

Here is the code I have written:

import spotipy
from spotipy.oauth2 import SpotifyOAuth

scope = "user-modify-playback-state,app-remote-control,streaming,user-read-playback-state"

sp = spotipy.Spotify(auth_manager=SpotifyOAuth(scope=scope), open_browser=False)

results = sp.devices()
print(results)

device = results['devices'][0]['id']

print(device)

results = sp.start_playback(device_id=device, context_uri="spotify:album:0d56QBHMTuBgehoYAZ2s25", offset={"position": 0})
print(results)

If a song is currently playing and I run my script, it just pauses whatever is playing and nothing else happens. If I have nothing playing, I get the following error:

HTTP Error for PUT to https://api.spotify.com/v1/me/player/pause with Params: {} returned 403 due to Player command failed: Restriction violated
Traceback (most recent call last):
  File "/home/zac/.local/lib/python3.9/site-packages/spotipy/client.py", line 271, in _internal_call
    response.raise_for_status()
  File "/usr/lib/python3/dist-packages/requests/models.py", line 943, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 403 Client Error: Forbidden for url: https://api.spotify.com/v1/me/player/pause

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/zac/RecordPi/Scripts/spotify.py", line 14, in <module>
    results = sp.pause_playback()
  File "/home/zac/.local/lib/python3.9/site-packages/spotipy/client.py", line 1831, in pause_playback
    return self._put(self._append_device_id("me/player/pause", device_id))
  File "/home/zac/.local/lib/python3.9/site-packages/spotipy/client.py", line 338, in _put
    return self._internal_call("PUT", url, payload, kwargs)
  File "/home/zac/.local/lib/python3.9/site-packages/spotipy/client.py", line 293, in _internal_call
    raise SpotifyException(
spotipy.exceptions.SpotifyException: http status: 403, code:-1 - https://api.spotify.com/v1/me/player/pause:
 Player command failed: Restriction violated, reason: UNKNOWN

I've got the spotify dev docs open and the request they've got works just fine, so I'm not sure where I went wrong in my code

Originally created by @ZacharyBrammer on GitHub (Mar 31, 2024). Original GitHub issue: https://github.com/spotipy-dev/spotipy/issues/1082 Hey y'all, just started using spotipy and I'm having issues getting playback to start. I'm trying to control music playing on my laptop (or whatever device) from a raspberry pi. Here is the code I have written: ``` import spotipy from spotipy.oauth2 import SpotifyOAuth scope = "user-modify-playback-state,app-remote-control,streaming,user-read-playback-state" sp = spotipy.Spotify(auth_manager=SpotifyOAuth(scope=scope), open_browser=False) results = sp.devices() print(results) device = results['devices'][0]['id'] print(device) results = sp.start_playback(device_id=device, context_uri="spotify:album:0d56QBHMTuBgehoYAZ2s25", offset={"position": 0}) print(results) ``` If a song is currently playing and I run my script, it just pauses whatever is playing and nothing else happens. If I have nothing playing, I get the following error: ``` HTTP Error for PUT to https://api.spotify.com/v1/me/player/pause with Params: {} returned 403 due to Player command failed: Restriction violated Traceback (most recent call last): File "/home/zac/.local/lib/python3.9/site-packages/spotipy/client.py", line 271, in _internal_call response.raise_for_status() File "/usr/lib/python3/dist-packages/requests/models.py", line 943, in raise_for_status raise HTTPError(http_error_msg, response=self) requests.exceptions.HTTPError: 403 Client Error: Forbidden for url: https://api.spotify.com/v1/me/player/pause During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/home/zac/RecordPi/Scripts/spotify.py", line 14, in <module> results = sp.pause_playback() File "/home/zac/.local/lib/python3.9/site-packages/spotipy/client.py", line 1831, in pause_playback return self._put(self._append_device_id("me/player/pause", device_id)) File "/home/zac/.local/lib/python3.9/site-packages/spotipy/client.py", line 338, in _put return self._internal_call("PUT", url, payload, kwargs) File "/home/zac/.local/lib/python3.9/site-packages/spotipy/client.py", line 293, in _internal_call raise SpotifyException( spotipy.exceptions.SpotifyException: http status: 403, code:-1 - https://api.spotify.com/v1/me/player/pause: Player command failed: Restriction violated, reason: UNKNOWN ``` I've got the [spotify dev docs open](https://developer.spotify.com/documentation/web-api/reference/start-a-users-playback) and the request they've got works just fine, so I'm not sure where I went wrong in my code
kerem 2026-02-28 00:00:28 +03:00
  • closed this issue
  • added the
    question
    label
Author
Owner

@ZacharyBrammer commented on GitHub (Mar 31, 2024):

So I just copied over the example code for playback into another file and now it works? Only difference it seems is that I have auth_manager=SpotifyOAuth instead of (client_credentials_manager=SpotifyOAuth. I don't know if that file is just cursed or what, but even when I replaced all of my code with the example it didn't work.

<!-- gh-comment-id:2028528889 --> @ZacharyBrammer commented on GitHub (Mar 31, 2024): So I just copied over the example code for playback into another file and now it works? Only difference it seems is that I have `auth_manager=SpotifyOAuth` instead of `(client_credentials_manager=SpotifyOAuth`. I don't know if that file is just cursed or what, but even when I replaced all of my code with the example it didn't work.
Author
Owner

@ZacharyBrammer commented on GitHub (Mar 31, 2024):

I deleted the old file and put my code in a new one and now it works. No clue what the issue was, but it's gone now

<!-- gh-comment-id:2028529400 --> @ZacharyBrammer commented on GitHub (Mar 31, 2024): I deleted the old file and put my code in a new one and now it works. No clue what the issue was, but it's gone now
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#640
No description provided.