[GH-ISSUE #1088] Receiving authentication error when using "current_user_playlists" #643

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

Originally created by @schebook on GitHub (Apr 24, 2024).
Original GitHub issue: https://github.com/spotipy-dev/spotipy/issues/1088

Hi all,

As the title says, I'm receiving an authentication error when using the current_user_playlists method. I'm able to run the examples in the Spotipy docs - as I believe they don't require user authentication. A cache file is generated when I run the program with a bearer token as well.

I have the Client ID, Client Secret and Redirect URI set as environment variables. Not too sure where I'm going wrong. I'm not sure if I need to switch authentication methods, apply a certain scope, or something else. I've attempted to feed SpotifyClientCredentials() a scope to read private playlists to no avail. Any ideas? Below is my code:

import spotipy
from spotipy.oauth2 import SpotifyClientCredentials
import os
import json

#Getting the client ID and client secret after making them environment varibales
client_id = os.environ.get('SPOTIPY_CLIENT_ID')
client_secret = os.environ.get('SPOTIPY_CLIENT_SECRET')

# print(client_id)
# print(client_secret)

#Performing a check to make sure that the environment variables are remembered.
if client_id is None or client_secret is None:
    print("ERROR: Set SPOTIPY_CLIENT_ID and SPOTIPY_CLIENT SECRET environment variables")

#Entering the URI of the playlist
playlist_uri = "spotify:playlist:37i9dQZF1EJzGGGOWOiITB"
spotify = spotipy.Spotify(client_credentials_manager=SpotifyClientCredentials())


# playlists = spotify.user_playlists("schebook")
# print(json.dumps(playlists, indent=4))

test = spotify.current_user_playlists(limit=20)
print(test)

and this is the error that I'm getting when trying to run:

{
  "error": {
    "status": 401,
    "message": "No token provided"
  }
}
Originally created by @schebook on GitHub (Apr 24, 2024). Original GitHub issue: https://github.com/spotipy-dev/spotipy/issues/1088 Hi all, As the title says, I'm receiving an authentication error when using the current_user_playlists method. I'm able to run the examples in the Spotipy docs - as I believe they don't require user authentication. A cache file is generated when I run the program with a bearer token as well. I have the Client ID, Client Secret and Redirect URI set as environment variables. Not too sure where I'm going wrong. I'm not sure if I need to switch authentication methods, apply a certain scope, or something else. I've attempted to feed SpotifyClientCredentials() a scope to read private playlists to no avail. Any ideas? Below is my code: ```python import spotipy from spotipy.oauth2 import SpotifyClientCredentials import os import json #Getting the client ID and client secret after making them environment varibales client_id = os.environ.get('SPOTIPY_CLIENT_ID') client_secret = os.environ.get('SPOTIPY_CLIENT_SECRET') # print(client_id) # print(client_secret) #Performing a check to make sure that the environment variables are remembered. if client_id is None or client_secret is None: print("ERROR: Set SPOTIPY_CLIENT_ID and SPOTIPY_CLIENT SECRET environment variables") #Entering the URI of the playlist playlist_uri = "spotify:playlist:37i9dQZF1EJzGGGOWOiITB" spotify = spotipy.Spotify(client_credentials_manager=SpotifyClientCredentials()) # playlists = spotify.user_playlists("schebook") # print(json.dumps(playlists, indent=4)) test = spotify.current_user_playlists(limit=20) print(test) ``` and this is the error that I'm getting when trying to run: ```javascript { "error": { "status": 401, "message": "No token provided" } } ```
kerem 2026-02-28 00:00:29 +03:00
  • closed this issue
  • added the
    question
    label
Author
Owner

@dieser-niko commented on GitHub (Apr 25, 2024):

You may want to replace SpotifyClientCredentials with SpotifyOAuth or the application will not have a user to work with. This also requires the addition of a SPOTIPY_REDIRECT_URI, but you won't get far without one either way.

Also, I'm not sure how you got a JSON output. Normally it throws an error. If there are some additions to your script, make sure to include them if related.

<!-- gh-comment-id:2077015557 --> @dieser-niko commented on GitHub (Apr 25, 2024): You may want to replace `SpotifyClientCredentials` with `SpotifyOAuth` or the application will not have a user to work with. This also requires the addition of a `SPOTIPY_REDIRECT_URI`, but you won't get far without one either way. Also, I'm not sure how you got a JSON output. Normally it throws an error. If there are some additions to your script, make sure to include them if related.
Author
Owner

@schebook commented on GitHub (Apr 25, 2024):

Thanks @dieser-niko ! Switching over to SpotifyOAuth allowed this to work. I got the JSON output via a link that was provided in the output. The link, when pasted into my browser, provided the JSON output. I think it's just Spotipy's way of creating an easier to read format.

<!-- gh-comment-id:2077810388 --> @schebook commented on GitHub (Apr 25, 2024): Thanks @dieser-niko ! Switching over to SpotifyOAuth allowed this to work. I got the JSON output via a link that was provided in the output. The link, when pasted into my browser, provided the JSON output. I think it's just Spotipy's way of creating an easier to read format.
Author
Owner

@schebook commented on GitHub (Apr 25, 2024):

Using SpotifyOAuth fixed the issue that I was having. Make sure to have a redirect URI as mentioned by @dieser-niko

<!-- gh-comment-id:2077811503 --> @schebook commented on GitHub (Apr 25, 2024): Using SpotifyOAuth fixed the issue that I was having. Make sure to have a redirect URI as mentioned by @dieser-niko
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#643
No description provided.