[GH-ISSUE #735] User authentication error -- any help would be appreciated! #443

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

Originally created by @joan0fsnark on GitHub (Oct 18, 2021).
Original GitHub issue: https://github.com/spotipy-dev/spotipy/issues/735

I've been unable to resolve this through Googling and I'm hoping someone more knowledgeable can point out what I need to do to resolve this:

spotipy.exceptions.SpotifyException: http status: 403, code:-1 - https://api.spotify.com/v1/playlists/2xrBNrvwtXN5Wvx54ZuWTP/tracks:
This request requires user authentication., reason: None

I've tried a couple of different authentication methods and while it works for read-only functions such as pulling a playlist, track info, etc., I keep getting an authentication error when I try to delete tracks from a playlist. (client_id and client_secret are currently hard-coded and are working/correct))

TIA!

import pprint
import spotipy
from spotipy.oauth2 import SpotifyClientCredentials

client_id="my-client-id"
client_secret="my-client-secret"

client_credentials_manager = SpotifyClientCredentials(client_id, client_secret)
sp = spotipy.Spotify(client_credentials_manager=client_credentials_manager) 
scope = 'playlist-modify-public'

def call_playlist(creator, playlist_id):
    playlist = sp.user_playlist_tracks(creator, playlist_id)["items"]

    playlist_features_list = ["artist","album","track_name",  "track_id", "instrumentalness"]

    for track in playlist:
        playlist_features = {} # Create empty dict

        # Get metadata
        playlist_features["artist"] = track["track"]["album"]["artists"][0]["name"]
        playlist_features["album"] = track["track"]["album"]["name"]
        playlist_features["track_name"] = track["track"]["name"]
        playlist_features["track_id"] = track["track"]["id"]
        
        # Get audio features
        audio_features = sp.audio_features(playlist_features["track_id"])[0]
        feature = playlist_features_list[4]
        playlist_features[feature] = audio_features[feature]
        instrumentalness = float(playlist_features['instrumentalness'])
        track_ids = []
        
        if instrumentalness < float(0.5):
            track_id = playlist_features["track_id"]
            track_ids.append(track_id)
        results = sp.playlist_remove_all_occurrences_of_items(playlist_id, track_ids)
        pprint.pprint(results)

call_playlist('user', '2MepDCzimtCz2ytAlLUdUi')
Originally created by @joan0fsnark on GitHub (Oct 18, 2021). Original GitHub issue: https://github.com/spotipy-dev/spotipy/issues/735 I've been unable to resolve this through Googling and I'm hoping someone more knowledgeable can point out what I need to do to resolve this: > spotipy.exceptions.SpotifyException: http status: 403, code:-1 - https://api.spotify.com/v1/playlists/2xrBNrvwtXN5Wvx54ZuWTP/tracks: > This request requires user authentication., reason: None I've tried a couple of different authentication methods and while it works for read-only functions such as pulling a playlist, track info, etc., I keep getting an authentication error when I try to delete tracks from a playlist. (client_id and client_secret are currently hard-coded and are working/correct)) TIA! ``` import pprint import spotipy from spotipy.oauth2 import SpotifyClientCredentials client_id="my-client-id" client_secret="my-client-secret" client_credentials_manager = SpotifyClientCredentials(client_id, client_secret) sp = spotipy.Spotify(client_credentials_manager=client_credentials_manager) scope = 'playlist-modify-public' def call_playlist(creator, playlist_id): playlist = sp.user_playlist_tracks(creator, playlist_id)["items"] playlist_features_list = ["artist","album","track_name", "track_id", "instrumentalness"] for track in playlist: playlist_features = {} # Create empty dict # Get metadata playlist_features["artist"] = track["track"]["album"]["artists"][0]["name"] playlist_features["album"] = track["track"]["album"]["name"] playlist_features["track_name"] = track["track"]["name"] playlist_features["track_id"] = track["track"]["id"] # Get audio features audio_features = sp.audio_features(playlist_features["track_id"])[0] feature = playlist_features_list[4] playlist_features[feature] = audio_features[feature] instrumentalness = float(playlist_features['instrumentalness']) track_ids = [] if instrumentalness < float(0.5): track_id = playlist_features["track_id"] track_ids.append(track_id) results = sp.playlist_remove_all_occurrences_of_items(playlist_id, track_ids) pprint.pprint(results) call_playlist('user', '2MepDCzimtCz2ytAlLUdUi') ```
kerem 2026-02-27 23:22:39 +03:00
  • closed this issue
  • added the
    question
    label
Author
Owner

@joan0fsnark commented on GitHub (Oct 22, 2021):

I was missing the auth step.

<!-- gh-comment-id:949972328 --> @joan0fsnark commented on GitHub (Oct 22, 2021): I was missing the auth step.
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#443
No description provided.