[GH-ISSUE #407] No token provided error when using artist_top_tracks() #241

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

Originally created by @AustinPoulson on GitHub (Dec 21, 2019).
Original GitHub issue: https://github.com/spotipy-dev/spotipy/issues/407

Sorry if this is the wrong place to post this. I keep getting a "No token provided" error when I build my app. The only function I'm using is artist_top_tracks(). On the scope page, spotify doesn't list this as a function that requires authorization. I tried getting an authorization key, but I'm having a hard time figuring it out. Does this function actually need the token, or am I doing something wrong?

import praw
import time
import random
import spotipy
import spotipy.util as util

class song:
	def __init__(ID, uri, title, artist, link):
		self.ID = ID
		self.uri = uri
		self.title = title
		self.artist = artist
		self.genre = genre
		self.link = link

artists = ['spotify:artist:2BZV6mW3awPKw0YA9QKoqC']

try: #to connect to reddit and spotify.
    #connect to reddit.
    reddit = praw.Reddit(client_id='',
                        client_secret='',
                        username='',
                        password='',
                        user_agent='')
    #token = util.prompt_for_user_token('username',client_id='',client_secret='',redirect_uri='http://localhost/')
    spotify = spotipy.Spotify(auth=None)
except Exception as e: #if the connection fails, tell the user and continue.
    print(e)
    print('Could not connect to one or more APIs')

try: #To initialize songs into individual song objects.
    songs = []
    counter = 0
    for artist in artists:
        print('1')
        for tracks in spotify.artist_top_tracks(artist):
            print('2')
            ID = counter
            uri = artist
            title = track['name']
            artistname = spotify.artists(artist)
            link = track['url']
            songs.append(song(ID, uri, title, artistname, link)) 
            counter += 1
except Exception as e:
    print(e)
    print('Could not initialize one or more songs.')





randomsong = random.randint(0, counter)

Originally created by @AustinPoulson on GitHub (Dec 21, 2019). Original GitHub issue: https://github.com/spotipy-dev/spotipy/issues/407 Sorry if this is the wrong place to post this. I keep getting a "No token provided" error when I build my app. The only function I'm using is artist_top_tracks(). On the scope page, spotify doesn't list this as a function that requires authorization. I tried getting an authorization key, but I'm having a hard time figuring it out. Does this function actually need the token, or am I doing something wrong? ``` import praw import time import random import spotipy import spotipy.util as util class song: def __init__(ID, uri, title, artist, link): self.ID = ID self.uri = uri self.title = title self.artist = artist self.genre = genre self.link = link artists = ['spotify:artist:2BZV6mW3awPKw0YA9QKoqC'] try: #to connect to reddit and spotify. #connect to reddit. reddit = praw.Reddit(client_id='', client_secret='', username='', password='', user_agent='') #token = util.prompt_for_user_token('username',client_id='',client_secret='',redirect_uri='http://localhost/') spotify = spotipy.Spotify(auth=None) except Exception as e: #if the connection fails, tell the user and continue. print(e) print('Could not connect to one or more APIs') try: #To initialize songs into individual song objects. songs = [] counter = 0 for artist in artists: print('1') for tracks in spotify.artist_top_tracks(artist): print('2') ID = counter uri = artist title = track['name'] artistname = spotify.artists(artist) link = track['url'] songs.append(song(ID, uri, title, artistname, link)) counter += 1 except Exception as e: print(e) print('Could not initialize one or more songs.') randomsong = random.randint(0, counter) ```
kerem closed this issue 2026-02-27 23:21:35 +03:00
Author
Owner

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

This is still the correct place to ask until we transfer the repository! Looks like you have not provided any authentication. User tokens and client tokens are a different thing. I think some sort of token needs to be provided always, so if not a user token (the endpoint action is not associated with a specific user), then it should be the client token. In the current/old version I think it's this function that is responsible for retrieving client tokens.

<!-- gh-comment-id:568174672 --> @felix-hilden commented on GitHub (Dec 21, 2019): This is still the correct place to ask until we transfer the repository! Looks like you have not provided any authentication. User tokens and client tokens are a different thing. I think some sort of token needs to be provided always, so if not a user token (the endpoint action is not associated with a specific user), then it should be the client token. In the current/old version I think it's [this](https://github.com/plamere/spotipy/blob/master/spotipy/oauth2.py#L55) function that is responsible for retrieving client tokens.
Author
Owner

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

Yes the doc is out of date but will update it soon. For now make sure you provide a token with the correct scope: user-top-read

<!-- gh-comment-id:570084713 --> @stephanebruckert commented on GitHub (Jan 1, 2020): Yes the doc is out of date but will update it soon. For now make sure you provide a token with the correct scope: `user-top-read`
Author
Owner

@felix-hilden commented on GitHub (Jan 1, 2020):

@stephanebruckert I don't think artist_top_tracks is a user-authenticated endpoint. A client token should do fine.

<!-- gh-comment-id:570086071 --> @felix-hilden commented on GitHub (Jan 1, 2020): @stephanebruckert I don't think `artist_top_tracks` is a user-authenticated endpoint. A client token should do fine.
Author
Owner

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

@felix-hilden thank you, you are right, I was looking at the user's endpoint

@AustinPoulson let us know if either helps:

token = util.prompt_for_user_token(username,
                                   client_id=SPOTIPY_CLIENT_ID,
                                   client_secret=SPOTIPY_CLIENT_SECRET,
                                   redirect_uri=SPOTIPY_REDIFECT_URI)
sp = spotipy.Spotify(auth=token)

Or if you are looking to work without connecting your own Spotify account:

client_credentials_manager = SpotifyClientCredentials(client_id=SPOTIPY_CLIENT_ID, 
                                                      client_secret=SPOTIPY_CLIENT_SECRET)
sp = spotipy.Spotify(client_credentials_manager=client_credentials_manager)

Also doc was updated, have another look https://spotipy.readthedocs.io/en/latest/

<!-- gh-comment-id:570087415 --> @stephanebruckert commented on GitHub (Jan 1, 2020): @felix-hilden thank you, you are right, I was looking at the user's endpoint @AustinPoulson let us know if either helps: token = util.prompt_for_user_token(username, client_id=SPOTIPY_CLIENT_ID, client_secret=SPOTIPY_CLIENT_SECRET, redirect_uri=SPOTIPY_REDIFECT_URI) sp = spotipy.Spotify(auth=token) Or if you are looking to work without connecting your own Spotify account: client_credentials_manager = SpotifyClientCredentials(client_id=SPOTIPY_CLIENT_ID, client_secret=SPOTIPY_CLIENT_SECRET) sp = spotipy.Spotify(client_credentials_manager=client_credentials_manager) Also doc was updated, have another look https://spotipy.readthedocs.io/en/latest/
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#241
No description provided.