[GH-ISSUE #97] Spotify denying access for valid Id #44

Closed
opened 2026-02-27 23:20:33 +03:00 by kerem · 1 comment
Owner

Originally created by @patalanov on GitHub (Jun 6, 2016).
Original GitHub issue: https://github.com/spotipy-dev/spotipy/issues/97

I am trying to access Spotify playlists using the spotipy and pbl libraries. See http://pbl.readthedocs.io/en/latest/ for the latter.

I have this:

import sys
from pbl import *
import spotipy
import spotipy.util as util


def fetch(): #pbl methods here

    classic_rock = Sample(PlaylistSource('Rock Classics'), sample_size=10)
    new_music = Sample(PlaylistSource('New Music Tuesday'), sample_size=5)
    combined = Shuffler(Concatenate([classic_rock, new_music]))
    show_source(combined)

scope = 'playlist-modify-public'

if len(sys.argv) > 1:
    username = sys.argv[1]
else:
    print "Usage: %s username" % (sys.argv[0],)
    sys.exit()

token = util.prompt_for_user_token(username, scope, client_id='a_valid_id', client_secret='a_valid_secret', redirect_uri='http://localhost:8888/callback')

if token:
    sp = spotipy.Spotify(auth=token)
    fetch()

If I bypass the snippet relative to pbl methods and the pbl function call above and proceed, I am granted access.

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", username

Otherwise access is denied, and I get spotipy.oauth2.SpotifyOauthError: No client id

what is going on here? please help.

Originally created by @patalanov on GitHub (Jun 6, 2016). Original GitHub issue: https://github.com/spotipy-dev/spotipy/issues/97 I am trying to access Spotify playlists using the **spotipy** and **pbl** libraries. See http://pbl.readthedocs.io/en/latest/ for the latter. I have this: ``` import sys from pbl import * import spotipy import spotipy.util as util def fetch(): #pbl methods here classic_rock = Sample(PlaylistSource('Rock Classics'), sample_size=10) new_music = Sample(PlaylistSource('New Music Tuesday'), sample_size=5) combined = Shuffler(Concatenate([classic_rock, new_music])) show_source(combined) scope = 'playlist-modify-public' if len(sys.argv) > 1: username = sys.argv[1] else: print "Usage: %s username" % (sys.argv[0],) sys.exit() token = util.prompt_for_user_token(username, scope, client_id='a_valid_id', client_secret='a_valid_secret', redirect_uri='http://localhost:8888/callback') if token: sp = spotipy.Spotify(auth=token) fetch() ``` If I bypass the snippet relative to pbl methods and the pbl function call above and proceed, I am granted access. ``` 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", username ``` Otherwise access is denied, and I get **spotipy.oauth2.SpotifyOauthError: No client id** what is going on here? please help.
kerem closed this issue 2026-02-27 23:20:34 +03:00
Author
Owner

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

It's not spotipy that is failing here but it is pbl. I should still be able to help you.

pbl is using the Client Credentials Flow flow to get an API token as you can see here
github.com/plamere/pbl@ae71c0b493/pbl/spotify_plugs.py (L415). It's not passing any client ID and secret as parameters, which means pbl is expecting that you set SPOTIPY_CLIENT_ID and SPOTIPY_CLIENT_SECRET as environment variables:

So to run your program, you can do:

SPOTIPY_CLIENT_ID=x SPOTIPY_CLIENT_SECRET=y python main.py

It should also fix https://github.com/plamere/pbl/issues/10

<!-- gh-comment-id:573443368 --> @stephanebruckert commented on GitHub (Jan 12, 2020): It's not spotipy that is failing here but it is pbl. I should still be able to help you. pbl is using the `Client Credentials Flow` flow to get an API token as you can see here https://github.com/plamere/pbl/blob/ae71c0b493e9cb6ecca5cc02fd3f51afa3fb8d07/pbl/spotify_plugs.py#L415. It's not passing any client ID and secret as parameters, which means pbl [is expecting](https://github.com/plamere/spotipy/blob/f54830e272bd401290979bc898fb817a2cea0c73/spotipy/oauth2.py#L49) that you set `SPOTIPY_CLIENT_ID` and `SPOTIPY_CLIENT_SECRET` as environment variables: So to run your program, you can do: SPOTIPY_CLIENT_ID=x SPOTIPY_CLIENT_SECRET=y python main.py It should also fix https://github.com/plamere/pbl/issues/10
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#44
No description provided.