[GH-ISSUE #384] Connect server-sided without webpage #227

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

Originally created by @dicecko on GitHub (Jun 28, 2019).
Original GitHub issue: https://github.com/spotipy-dev/spotipy/issues/384

Hi I looked through a lot of documentation and issues, but I cannot find how I can just login through a python script and request my own data.

So I don't want to create a public app or something through the web. I just simply want to get my data back. Everything server-sided in a single py script without a frontend.

When I try this:

scope = 'user-library-read'

sp = spotipy.oauth2.SpotifyOAuth(client_id=client_id, client_secret=client_secret,scope=scope, 
          redirect_uri='')
print(sp)
token = sp.get_access_token()
print(token)
if token:
       sp = spotipy.Spotify(auth=token)
       results = sp.current_user_saved_tracks()
       for item in results['items']:
            track = item['track']
            print(track['name'] + ' - ' + track['artists'][0]['name'])
else:
         print("Can't get token for " + client_id)

I get the error:

TypeError Traceback (most recent call last)
in ()
3 sp = spotipy.oauth2.SpotifyOAuth(client_id=client_id, client_secret=client_secret,scope=scope, redirect_uri='')
4 print(sp)
----> 5 token = sp.get_access_token()
6 print(token)
7 if token:

TypeError: get_access_token() missing 1 required positional argument: 'code'

I also just tried it directly with the requests module:

grant_type = 'client_credentials'

#Request based on Client Credentials Flow from https://developer.spotify.com/web-api/authorization-guide/

#Request body parameter: grant_type Value: Required. Set it to client_credentials
body_params = {'grant_type' : grant_type}

url='https://accounts.spotify.com/api/token'

response=requests.post(url, data=body_params, auth = (client_id, client_secret)) 

token = response.json()['access_token']

but then I get the error:
SpotifyException: http status: 403, code:-1 - https://api.spotify.com/v1/me/tracks?offset=0&limit=20:
Insufficient client scope

But I have no idea where to add the scopes. I tried adding it in grant_type and as a seperate key-value pair in body_params, but that doesn't work.

Originally created by @dicecko on GitHub (Jun 28, 2019). Original GitHub issue: https://github.com/spotipy-dev/spotipy/issues/384 Hi I looked through a lot of documentation and issues, but I cannot find how I can just login through a python script and request my own data. So I don't want to create a public app or something through the web. I just simply want to get my data back. Everything server-sided in a single py script without a frontend. When I try this: ``` scope = 'user-library-read' sp = spotipy.oauth2.SpotifyOAuth(client_id=client_id, client_secret=client_secret,scope=scope, redirect_uri='') print(sp) token = sp.get_access_token() print(token) if token: sp = spotipy.Spotify(auth=token) results = sp.current_user_saved_tracks() for item in results['items']: track = item['track'] print(track['name'] + ' - ' + track['artists'][0]['name']) else: print("Can't get token for " + client_id) ``` I get the error: --------------------------------------------------------------------------- TypeError Traceback (most recent call last) <ipython-input-26-f05d69aac870> in <module>() 3 sp = spotipy.oauth2.SpotifyOAuth(client_id=client_id, client_secret=client_secret,scope=scope, redirect_uri='') 4 print(sp) ----> 5 token = sp.get_access_token() 6 print(token) 7 if token: TypeError: get_access_token() missing 1 required positional argument: 'code' I also just tried it directly with the requests module: ``` grant_type = 'client_credentials' #Request based on Client Credentials Flow from https://developer.spotify.com/web-api/authorization-guide/ #Request body parameter: grant_type Value: Required. Set it to client_credentials body_params = {'grant_type' : grant_type} url='https://accounts.spotify.com/api/token' response=requests.post(url, data=body_params, auth = (client_id, client_secret)) token = response.json()['access_token'] ``` but then I get the error: SpotifyException: http status: 403, code:-1 - https://api.spotify.com/v1/me/tracks?offset=0&limit=20: Insufficient client scope But I have no idea where to add the scopes. I tried adding it in grant_type and as a seperate key-value pair in body_params, but that doesn't work.
kerem closed this issue 2026-02-27 23:21:29 +03:00
Author
Owner

@sibo7851 commented on GitHub (Sep 19, 2019):

I'm under the impression that this plugin is not actively developed, and I don't think it even works if you have a website setup (since I tried it using my sites working redirect URI and it did not give me python access).

<!-- gh-comment-id:533244690 --> @sibo7851 commented on GitHub (Sep 19, 2019): I'm under the impression that this plugin is not actively developed, and I don't think it even works if you have a website setup (since I tried it using my sites working redirect URI and it did not give me python access).
Author
Owner

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

It most certainly does work for a website setup! And maintenance is being continued. Have a look at #406.

For local use, you probably want to use util.promp_for_user_token to retrieve a token. That's very handy for single-user situations and small scripts. Have a look at the documentation for more information!

And let me clarify, a browser window is absolutely needed for user authentication, whether that is spawned by a web app or just opened up locally. That's part of the OAuth2 specification. The application token can be retrieved without any browsers, but the user needs to manually grant access to your application.

<!-- gh-comment-id:569334021 --> @felix-hilden commented on GitHub (Dec 27, 2019): It most certainly does work for a website setup! And maintenance is being continued. Have a look at #406. For local use, you probably want to use `util.promp_for_user_token` to retrieve a token. That's very handy for single-user situations and small scripts. Have a look at the documentation for more information! And let me clarify, a browser window is absolutely needed for user authentication, whether that is spawned by a web app or just opened up locally. That's part of the OAuth2 specification. The application token can be retrieved without any browsers, but the user needs to manually grant access to your application.
Author
Owner

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

Answered by @felix-hilden, closing

<!-- gh-comment-id:573347418 --> @stephanebruckert commented on GitHub (Jan 11, 2020): Answered by @felix-hilden, closing
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#227
No description provided.