[GH-ISSUE #704] PREMIUM REQUIRED, chosen the correct oauth flow :/ #417

Closed
opened 2026-02-27 23:22:30 +03:00 by kerem · 7 comments
Owner

Originally created by @Pancham1603 on GitHub (Jul 10, 2021).
Original GitHub issue: https://github.com/spotipy-dev/spotipy/issues/704

import requests
from spotipy import oauth2
import spotipy
from flask import Flask

app = Flask(__name__)
app.secret_key = 'demo'

SPOTIPY_CLIENT_ID = ''
SPOTIPY_CLIENT_SECRET = ''
SPOTIPY_REDIRECT_URI = 'http://localhost:5000'
SCOPE = 'user-modify-playback-state'
CACHE = '.spotipyoauthcache'

oauth = oauth2.SpotifyOAuth(SPOTIPY_CLIENT_ID,SPOTIPY_CLIENT_SECRET, SPOTIPY_REDIRECT_URI,show_dialog=True,scope=SCOPE, cache_path=CACHE)

@app.route('/')
def home():
    token_info = oauth.get_access_token('AQCT875sQScxnBgJ-Ua05p6aXY0DATH6v3VVJG-jACCXY8gMbFk2-OsS-aZrrE17J4nOXY-ynEd1uQc5O1vmRi58QeEJ0IbB7vdspdoaX5GSESLQFhbAUdXs7JJxn892ScBE3-SvEJmFWJ7wwoQOJvJTcFw04aZplRracerzRVE-Wdh-VplPDsx4FxIs8OqoaqIC_5M')
    sp = spotipy.Spotify(token_info['access_token'])
    results = sp.current_user()
    sp.start_playback(uris=['3K7vPyMCcecKRotnu08MMP'])
    return results


if __name__ == '__main__':
    app.run() 

I am trying to start playback, but it gives an error that Premium is required. I read several articles they say that choosing the correct oauth will fix this but the error still persists.

Traceback (most recent call last):
  File "/Users/pancham/opt/anaconda3/lib/python3.8/site-packages/spotipy/client.py", line 245, in _internal_call
    response.raise_for_status()
  File "/Users/pancham/opt/anaconda3/lib/python3.8/site-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/play

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/pancham/opt/anaconda3/lib/python3.8/site-packages/flask/app.py", line 2447, in wsgi_app
    response = self.full_dispatch_request()
  File "/Users/pancham/opt/anaconda3/lib/python3.8/site-packages/flask/app.py", line 1952, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/Users/pancham/opt/anaconda3/lib/python3.8/site-packages/flask/app.py", line 1821, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/Users/pancham/opt/anaconda3/lib/python3.8/site-packages/flask/_compat.py", line 39, in reraise
    raise value
  File "/Users/pancham/opt/anaconda3/lib/python3.8/site-packages/flask/app.py", line 1950, in full_dispatch_request
    rv = self.dispatch_request()
  File "/Users/pancham/opt/anaconda3/lib/python3.8/site-packages/flask/app.py", line 1936, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/Users/pancham/Documents/ctcrypt alexa/main.py", line 29, in home
  File "/Users/pancham/opt/anaconda3/lib/python3.8/site-packages/spotipy/client.py", line 1709, in start_playback
    return self._put(
  File "/Users/pancham/opt/anaconda3/lib/python3.8/site-packages/spotipy/client.py", line 306, in _put
    return self._internal_call("PUT", url, payload, kwargs)
  File "/Users/pancham/opt/anaconda3/lib/python3.8/site-packages/spotipy/client.py", line 261, in _internal_call
    raise SpotifyException(
spotipy.exceptions.SpotifyException: http status: 403, code:-1 - https://api.spotify.com/v1/me/player/play:
 Player command failed: Premium required, reason: PREMIUM_REQUIRED
Originally created by @Pancham1603 on GitHub (Jul 10, 2021). Original GitHub issue: https://github.com/spotipy-dev/spotipy/issues/704 ``` import requests from spotipy import oauth2 import spotipy from flask import Flask app = Flask(__name__) app.secret_key = 'demo' SPOTIPY_CLIENT_ID = '' SPOTIPY_CLIENT_SECRET = '' SPOTIPY_REDIRECT_URI = 'http://localhost:5000' SCOPE = 'user-modify-playback-state' CACHE = '.spotipyoauthcache' oauth = oauth2.SpotifyOAuth(SPOTIPY_CLIENT_ID,SPOTIPY_CLIENT_SECRET, SPOTIPY_REDIRECT_URI,show_dialog=True,scope=SCOPE, cache_path=CACHE) @app.route('/') def home(): token_info = oauth.get_access_token('AQCT875sQScxnBgJ-Ua05p6aXY0DATH6v3VVJG-jACCXY8gMbFk2-OsS-aZrrE17J4nOXY-ynEd1uQc5O1vmRi58QeEJ0IbB7vdspdoaX5GSESLQFhbAUdXs7JJxn892ScBE3-SvEJmFWJ7wwoQOJvJTcFw04aZplRracerzRVE-Wdh-VplPDsx4FxIs8OqoaqIC_5M') sp = spotipy.Spotify(token_info['access_token']) results = sp.current_user() sp.start_playback(uris=['3K7vPyMCcecKRotnu08MMP']) return results if __name__ == '__main__': app.run() ``` I am trying to start playback, but it gives an error that Premium is required. I read several articles they say that choosing the correct oauth will fix this but the error still persists. ``` Traceback (most recent call last): File "/Users/pancham/opt/anaconda3/lib/python3.8/site-packages/spotipy/client.py", line 245, in _internal_call response.raise_for_status() File "/Users/pancham/opt/anaconda3/lib/python3.8/site-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/play During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/Users/pancham/opt/anaconda3/lib/python3.8/site-packages/flask/app.py", line 2447, in wsgi_app response = self.full_dispatch_request() File "/Users/pancham/opt/anaconda3/lib/python3.8/site-packages/flask/app.py", line 1952, in full_dispatch_request rv = self.handle_user_exception(e) File "/Users/pancham/opt/anaconda3/lib/python3.8/site-packages/flask/app.py", line 1821, in handle_user_exception reraise(exc_type, exc_value, tb) File "/Users/pancham/opt/anaconda3/lib/python3.8/site-packages/flask/_compat.py", line 39, in reraise raise value File "/Users/pancham/opt/anaconda3/lib/python3.8/site-packages/flask/app.py", line 1950, in full_dispatch_request rv = self.dispatch_request() File "/Users/pancham/opt/anaconda3/lib/python3.8/site-packages/flask/app.py", line 1936, in dispatch_request return self.view_functions[rule.endpoint](**req.view_args) File "/Users/pancham/Documents/ctcrypt alexa/main.py", line 29, in home File "/Users/pancham/opt/anaconda3/lib/python3.8/site-packages/spotipy/client.py", line 1709, in start_playback return self._put( File "/Users/pancham/opt/anaconda3/lib/python3.8/site-packages/spotipy/client.py", line 306, in _put return self._internal_call("PUT", url, payload, kwargs) File "/Users/pancham/opt/anaconda3/lib/python3.8/site-packages/spotipy/client.py", line 261, in _internal_call raise SpotifyException( spotipy.exceptions.SpotifyException: http status: 403, code:-1 - https://api.spotify.com/v1/me/player/play: Player command failed: Premium required, reason: PREMIUM_REQUIRED ```
kerem 2026-02-27 23:22:30 +03:00
  • closed this issue
  • added the
    question
    label
Author
Owner

@stephanebruckert commented on GitHub (Jul 10, 2021):

If you print result (the current user), what do you get? Please do this before calling sp.start_playback

Other notes:

  • try not to share your "code" (AQCT875sQScxnBgJ-Ua05p6....) publicly

  • it's not clear what kind of code that is, user or credentials?

  • you are using older methods which makes it a bit more difficult to help. Can you try to adapt your development code to a new method? https://github.com/plamere/spotipy/blob/master/examples/player.py

    scope = "user-read-playback-state,user-modify-playback-state"
    sp = spotipy.Spotify(client_credentials_manager=SpotifyOAuth(scope=scope))
    

    Edit: actually I just noticed the example is not entirely correct, it should be:

    scope = "user-read-playback-state,user-modify-playback-state"
    sp = spotipy.Spotify(auth_manager=SpotifyOAuth(scope=scope))
    
<!-- gh-comment-id:877611325 --> @stephanebruckert commented on GitHub (Jul 10, 2021): If you print `result` (the current user), what do you get? Please do this before calling `sp.start_playback` Other notes: - try not to share your "code" (AQCT875sQScxnBgJ-Ua05p6....) publicly - it's not clear what kind of code that is, user or credentials? - you are using older methods which makes it a bit more difficult to help. Can you try to adapt your development code to a new method? https://github.com/plamere/spotipy/blob/master/examples/player.py ```python scope = "user-read-playback-state,user-modify-playback-state" sp = spotipy.Spotify(client_credentials_manager=SpotifyOAuth(scope=scope)) ``` Edit: actually I just noticed the example is not entirely correct, it should be: ```python scope = "user-read-playback-state,user-modify-playback-state" sp = spotipy.Spotify(auth_manager=SpotifyOAuth(scope=scope)) ```
Author
Owner

@Peter-Schorn commented on GitHub (Jul 10, 2021):

The error should be self-explanatory: You need a Spotify premium account to use this endpoint.

Also, "3K7vPyMCcecKRotnu08MMP" is not a URI. It should be "spotify:track:3K7vPyMCcecKRotnu08MMP".

<!-- gh-comment-id:877646516 --> @Peter-Schorn commented on GitHub (Jul 10, 2021): The error should be self-explanatory: You need a Spotify premium account to use this endpoint. Also, "3K7vPyMCcecKRotnu08MMP" is not a URI. It should be "spotify:track:3K7vPyMCcecKRotnu08MMP".
Author
Owner

@Pancham1603 commented on GitHub (Jul 11, 2021):

@stephanebruckert

{'display_name': 'Pancham', 
 'external_urls': {'spotify': 'https://open.spotify.com/user/0l8lvp99qtlkx87lufuj1c0jd'},
 'followers': {'href': None, 'total': 10},
 'href': 'https://api.spotify.com/v1/users/0l8lvp99qtlkx87lufuj1c0jd',
 'id': '0l8lvp99qtlkx87lufuj1c0jd',
 'images': [{'height': None, 'url': 'https://i.scdn.co/image/ab6775700000ee85405317ef998f50e24dcf764f', 'width': None}],
 'type': 'user',
 'uri': 'spotify:user:0l8lvp99qtlkx87lufuj1c0jd'}

This is what i get and it works fine but the PREMIUM_REQUIRED error still persists, just wanted to know if there's any way to control non premium spotify accounts?

Adapted the code according to the example:

from spotipy import oauth2, SpotifyOAuth
import spotipy

SPOTIPY_CLIENT_ID = ''
SPOTIPY_CLIENT_SECRET = ''
SPOTIPY_REDIRECT_URI = 'http://localhost:5000'
SCOPE = "user-read-playback-state,user-modify-playback-state"

sp = spotipy.Spotify(auth_manager=SpotifyOAuth(scope=SCOPE, client_id=SPOTIPY_CLIENT_ID, client_secret=SPOTIPY_CLIENT_SECRET, redirect_uri=SPOTIPY_REDIRECT_URI))
res = sp.devices()
print(res)
results = sp.current_user()
print(results)

sp.start_playback(uris=['spotify:track:3K7vPyMCcecKRotnu08MMP'])

It even shows the devices and everything currently, actually i am looking forward to build a big project on remote controlling the accounts but just trying the main thing first because i want it to work for non-premium accounts. If there's any way to do so then please let me know. Thanks

Also that code was my one time expired access token oof

<!-- gh-comment-id:877728623 --> @Pancham1603 commented on GitHub (Jul 11, 2021): @stephanebruckert ``` {'display_name': 'Pancham', 'external_urls': {'spotify': 'https://open.spotify.com/user/0l8lvp99qtlkx87lufuj1c0jd'}, 'followers': {'href': None, 'total': 10}, 'href': 'https://api.spotify.com/v1/users/0l8lvp99qtlkx87lufuj1c0jd', 'id': '0l8lvp99qtlkx87lufuj1c0jd', 'images': [{'height': None, 'url': 'https://i.scdn.co/image/ab6775700000ee85405317ef998f50e24dcf764f', 'width': None}], 'type': 'user', 'uri': 'spotify:user:0l8lvp99qtlkx87lufuj1c0jd'} ``` This is what i get and it works fine but the PREMIUM_REQUIRED error still persists, just wanted to know if there's any way to control non premium spotify accounts? Adapted the code according to the example: ``` from spotipy import oauth2, SpotifyOAuth import spotipy SPOTIPY_CLIENT_ID = '' SPOTIPY_CLIENT_SECRET = '' SPOTIPY_REDIRECT_URI = 'http://localhost:5000' SCOPE = "user-read-playback-state,user-modify-playback-state" sp = spotipy.Spotify(auth_manager=SpotifyOAuth(scope=SCOPE, client_id=SPOTIPY_CLIENT_ID, client_secret=SPOTIPY_CLIENT_SECRET, redirect_uri=SPOTIPY_REDIRECT_URI)) res = sp.devices() print(res) results = sp.current_user() print(results) sp.start_playback(uris=['spotify:track:3K7vPyMCcecKRotnu08MMP']) ``` It even shows the devices and everything currently, actually i am looking forward to build a big project on remote controlling the accounts but just trying the main thing first because i want it to work for non-premium accounts. If there's any way to do so then please let me know. Thanks Also that code was my one time `expired` access token oof
Author
Owner

@Pancham1603 commented on GitHub (Jul 11, 2021):

The error should be self-explanatory: You need a Spotify premium account to use this endpoint.

Also, "3K7vPyMCcecKRotnu08MMP" is not a URI. It should be "spotify:track:3K7vPyMCcecKRotnu08MMP".

fixed that thanks

<!-- gh-comment-id:877728675 --> @Pancham1603 commented on GitHub (Jul 11, 2021): > The error should be self-explanatory: You need a Spotify premium account to use this endpoint. > > Also, "3K7vPyMCcecKRotnu08MMP" is not a URI. It should be "spotify:track:3K7vPyMCcecKRotnu08MMP". fixed that thanks
Author
Owner

@Peter-Schorn commented on GitHub (Jul 11, 2021):

but the PREMIUM_REQUIRED error still persists, just wanted to know if there's any way to control non premium spotify accounts?

If the error says "PREMIUM_REQUIRED", then premium is required. Period. There's no way of getting around that.

<!-- gh-comment-id:877730128 --> @Peter-Schorn commented on GitHub (Jul 11, 2021): > but the PREMIUM_REQUIRED error still persists, just wanted to know if there's any way to control non premium spotify accounts? If the error says "PREMIUM_REQUIRED", then premium is required. Period. There's no way of getting around that.
Author
Owner

@masakk1 commented on GitHub (Oct 26, 2023):

Hey, very sorry to bump this issue. But I was wondering, why does Spotipy not allow free accounts? Spotify TUI is written in rust but it is able to control playback state and it does not require PREMIUM. I know for a fact that telling spotify "play this playlist" is possible on many other apps. Is this a limitation of Spotipy then?

Oh and now the spotify Web API says "free or premium" which I also found confusing.

if this is offtopic and I should make a new issue I'll do exactly that

<!-- gh-comment-id:1781082272 --> @masakk1 commented on GitHub (Oct 26, 2023): Hey, very sorry to bump this issue. But I was wondering, why does Spotipy not allow free accounts? Spotify TUI is written in rust but it is able to control playback state and it does not require PREMIUM. I know for a fact that telling spotify "play this playlist" is possible on many other apps. Is this a limitation of Spotipy then? Oh and now the spotify Web API says "free or premium" which I also found confusing. _if this is offtopic and I should make a new issue I'll do exactly that_
Author
Owner

@dieser-niko commented on GitHub (Nov 4, 2023):

Spotify obviously has more than the Web API, mostly for their front end. The spotipy library only uses the Web API. I don't know the exact reason why the others aren't implemented, but it might be because the rest has little to no official documentation and the function could change in the future without knowing it.

<!-- gh-comment-id:1793545223 --> @dieser-niko commented on GitHub (Nov 4, 2023): Spotify obviously has more than the Web API, mostly for their front end. The spotipy library only uses the Web API. I don't know the exact reason why the others aren't implemented, but it might be because the rest has little to no official documentation and the function could change in the future without knowing it.
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#417
No description provided.