[GH-ISSUE #408] start_playback(deviceID) returns "Player command failed: Restriction violated" #243

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

Originally created by @jpringle1 on GitHub (Dec 26, 2019).
Original GitHub issue: https://github.com/spotipy-dev/spotipy/issues/408

When using spotipy to start_playback on my phone, music resumes as expected. However, when i input the ID of my Amazon echo, it returns the error "Player command failed: Restriction violated".

Any idea what's causing this?

Originally created by @jpringle1 on GitHub (Dec 26, 2019). Original GitHub issue: https://github.com/spotipy-dev/spotipy/issues/408 When using spotipy to start_playback on my phone, music resumes as expected. However, when i input the ID of my Amazon echo, it returns the error "Player command failed: Restriction violated". Any idea what's causing this?
kerem closed this issue 2026-02-27 23:21:35 +03:00
Author
Owner

@felix-hilden commented on GitHub (Dec 26, 2019):

Could you please provide some more information? Were you already playing on the Echo, but then paused, or were you playing on your phone and tried to resume on the Echo, or what was the exact situation?

Perhaps you could try transferring the playback.

<!-- gh-comment-id:569133723 --> @felix-hilden commented on GitHub (Dec 26, 2019): Could you please provide some more information? Were you already playing on the Echo, but then paused, or were you playing on your phone and tried to resume on the Echo, or what was the exact situation? Perhaps you could try [transferring](https://github.com/plamere/spotipy/blob/master/spotipy/client.py#L901) the playback.
Author
Owner

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

Definitely this error is coming from the web API. Look at this thread https://github.com/spotify/web-api/issues/1205

<!-- gh-comment-id:573426616 --> @stephanebruckert commented on GitHub (Jan 12, 2020): Definitely this error is coming from the web API. Look at this thread https://github.com/spotify/web-api/issues/1205
Author
Owner

@d00mfish commented on GitHub (Jan 29, 2021):

So I have the same behaviour:

  1. Play music on spotify connect device, e.g. Echo Dot.
  2. Switch playback to pc in the spotify desktop app.
  3. Close the desktop app
  4. Start playback on spotify connect device (Echo) through python
  5. -> Restriction violated, even though the device id shows up in sp.devices() meaning the device is not gone like the PC-device
spotipy.exceptions.SpotifyException: http status: 403, code:-1 - https://api.spotify.com/v1/me/player/shuffle?state=true&device_id=bf4d8232a38775f80a75270e6cd9cad53b92d229:
 Player command failed: Restriction violated, reason: UNKNOWN

You think this is a web api issue?
If so, I will go there with my problem.

<!-- gh-comment-id:769981587 --> @d00mfish commented on GitHub (Jan 29, 2021): So I have the same behaviour: 1. Play music on spotify connect device, e.g. Echo Dot. 2. Switch playback to pc in the spotify desktop app. 3. Close the desktop app 4. Start playback on spotify connect device (Echo) through python 5. -> Restriction violated, even though the device id shows up in sp.devices() meaning the device is not _gone_ like the PC-device ``` spotipy.exceptions.SpotifyException: http status: 403, code:-1 - https://api.spotify.com/v1/me/player/shuffle?state=true&device_id=bf4d8232a38775f80a75270e6cd9cad53b92d229: Player command failed: Restriction violated, reason: UNKNOWN ``` You think this is a web api issue? If so, I will go there with my problem.
Author
Owner

@d00mfish commented on GitHub (Jan 29, 2021):

Alright so I worked around this with transferring the playback before, if a device is currently playing or if no device is playing at all.
Seems to work for now but is not that pretty. Alse I need to pause the playback, otherwise the currently playing song will shortly play on the echo:

def play_context_URI(uri: str):
    current = current_device()
    if current == -1:
        sp.transfer_playback(config['AUTH']['device_id'], force_play=False)        #Workaround for permission problems when old playback was on other device
        time.sleep(0.5)
        sp.pause_playback()
    elif current[0] != config['AUTH']['device_id']:
        sp.transfer_playback(config['AUTH']['device_id'], force_play=False)        #Workaround for permission problems when other device is currently in playback
        time.sleep(0.5)
        sp.pause_playback()
    if check_available(config['AUTH']['device_id']):         #check if device is even online for playback
        shuffle_on()
        sp.start_playback(device_id=config['AUTH']['device_id'], context_uri=uri)
        return 1
    else:
        return -1
<!-- gh-comment-id:770000939 --> @d00mfish commented on GitHub (Jan 29, 2021): Alright so I worked around this with transferring the playback before, if a device is currently playing or if no device is playing at all. Seems to work for now but is not that pretty. Alse I need to pause the playback, otherwise the currently playing song will shortly play on the echo: ```py def play_context_URI(uri: str): current = current_device() if current == -1: sp.transfer_playback(config['AUTH']['device_id'], force_play=False) #Workaround for permission problems when old playback was on other device time.sleep(0.5) sp.pause_playback() elif current[0] != config['AUTH']['device_id']: sp.transfer_playback(config['AUTH']['device_id'], force_play=False) #Workaround for permission problems when other device is currently in playback time.sleep(0.5) sp.pause_playback() if check_available(config['AUTH']['device_id']): #check if device is even online for playback shuffle_on() sp.start_playback(device_id=config['AUTH']['device_id'], context_uri=uri) return 1 else: return -1 ```
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#243
No description provided.