[GH-ISSUE #380] problem creating playlist/adding tracks #225

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

Originally created by @aced125 on GitHub (Jun 10, 2019).
Original GitHub issue: https://github.com/spotipy-dev/spotipy/issues/380

I am able to do the example where I can read one's saved tracks successfully (which requires authorisation).

However, when trying to create a playlist or modify it (I have included the relevant stuff in the scope), I get a http status: 405, code:-1 error. A link is then provided (https://api.spotify.com/v1/users/217plpxgwl26mxqkdifiyrndy?si=9cHjQNLQQOGzJQ6OuieIgQ/playlists:) saying no token is provided even though I think I have provided the token.

Here is my code:

import spotipy.util as util
scope = 'user-library-read playlist-read-private playlist-modify-private playlist-modify-public playlist-read-collaborative'

token = util.prompt_for_user_token(username,
client_id='my_client_id', 
client_secret='my_client_secret',
redirect_uri='http://localhost/',
scope = scope)

if token:
    sp = spotipy.Spotify(auth = token, client_credentials_manager= client_credentials_manager)
    sp.trace = False
    playlist_name = 'test1'
    playlist_description = 'description for test playlist'
    playlists = sp.user_playlist_create(username, playlist_name, public=False, description = playlist_description)

Here is the error message:

HTTPError Traceback (most recent call last)
~\Anaconda3\lib\site-packages\spotipy\client.py in _internal_call(self, method, url, payload, params)
120 try:
--> 121 r.raise_for_status()
122 except:

~\Anaconda3\lib\site-packages\requests\models.py in raise_for_status(self)
939 if http_error_msg:
--> 940 raise HTTPError(http_error_msg, response=self)
941

HTTPError: 405 Client Error: Method Not Allowed for url: https://api.spotify.com/v1/users/217plpxgwl26mxqkdifiyrndy?si=9cHjQNLQQOGzJQ6OuieIgQ/playlists

During handling of the above exception, another exception occurred:

SpotifyException Traceback (most recent call last)
in
13 playlist_name = 'test1'
14 playlist_description = 'description for test playlist'
---> 15 playlists = sp.user_playlist_create(username, playlist_name, public=False, description = playlist_description)

~\Anaconda3\lib\site-packages\spotipy\client.py in user_playlist_create(self, user, name, public, description)
413
414
--> 415 return self._post("users/%s/playlists" % (user,), payload=data)
416
417 def user_playlist_change_details(

~\Anaconda3\lib\site-packages\spotipy\client.py in _post(self, url, args, payload, **kwargs)
178 if args:
179 kwargs.update(args)
--> 180 return self._internal_call('POST', url, payload, kwargs)
181
182 def _delete(self, url, args=None, payload=None, **kwargs):

~\Anaconda3\lib\site-packages\spotipy\client.py in _internal_call(self, method, url, payload, params)
127 else:
128 raise SpotifyException(r.status_code,
--> 129 -1, '%s:\n %s' % (r.url, 'error'), headers=r.headers)
130 finally:
131 r.connection.close()

SpotifyException: http status: 405, code:-1 - https://api.spotify.com/v1/users/217plpxgwl26mxqkdifiyrndy?si=9cHjQNLQQOGzJQ6OuieIgQ/playlists:
error

Thanks in advance anyone who can help out!

Originally created by @aced125 on GitHub (Jun 10, 2019). Original GitHub issue: https://github.com/spotipy-dev/spotipy/issues/380 I am able to do the example where I can read one's saved tracks successfully (which requires authorisation). However, when trying to create a playlist or modify it (I have included the relevant stuff in the scope), I get a http status: 405, code:-1 error. A link is then provided (https://api.spotify.com/v1/users/217plpxgwl26mxqkdifiyrndy?si=9cHjQNLQQOGzJQ6OuieIgQ/playlists:) saying no token is provided even though I think I have provided the token. Here is my code: ``` import spotipy.util as util scope = 'user-library-read playlist-read-private playlist-modify-private playlist-modify-public playlist-read-collaborative' token = util.prompt_for_user_token(username, client_id='my_client_id', client_secret='my_client_secret', redirect_uri='http://localhost/', scope = scope) if token: sp = spotipy.Spotify(auth = token, client_credentials_manager= client_credentials_manager) sp.trace = False playlist_name = 'test1' playlist_description = 'description for test playlist' playlists = sp.user_playlist_create(username, playlist_name, public=False, description = playlist_description) ``` Here is the error message: > > HTTPError Traceback (most recent call last) > ~\Anaconda3\lib\site-packages\spotipy\client.py in _internal_call(self, method, url, payload, params) > 120 try: > --> 121 r.raise_for_status() > 122 except: > > ~\Anaconda3\lib\site-packages\requests\models.py in raise_for_status(self) > 939 if http_error_msg: > --> 940 raise HTTPError(http_error_msg, response=self) > 941 > > HTTPError: 405 Client Error: Method Not Allowed for url: https://api.spotify.com/v1/users/217plpxgwl26mxqkdifiyrndy?si=9cHjQNLQQOGzJQ6OuieIgQ/playlists > > During handling of the above exception, another exception occurred: > > SpotifyException Traceback (most recent call last) > <ipython-input-37-e5a050e7cee8> in <module> > 13 playlist_name = 'test1' > 14 playlist_description = 'description for test playlist' > ---> 15 playlists = sp.user_playlist_create(username, playlist_name, public=False, description = playlist_description) > > ~\Anaconda3\lib\site-packages\spotipy\client.py in user_playlist_create(self, user, name, public, description) > 413 > 414 > --> 415 return self._post("users/%s/playlists" % (user,), payload=data) > 416 > 417 def user_playlist_change_details( > > ~\Anaconda3\lib\site-packages\spotipy\client.py in _post(self, url, args, payload, **kwargs) > 178 if args: > 179 kwargs.update(args) > --> 180 return self._internal_call('POST', url, payload, kwargs) > 181 > 182 def _delete(self, url, args=None, payload=None, **kwargs): > > ~\Anaconda3\lib\site-packages\spotipy\client.py in _internal_call(self, method, url, payload, params) > 127 else: > 128 raise SpotifyException(r.status_code, > --> 129 -1, '%s:\n %s' % (r.url, 'error'), headers=r.headers) > 130 finally: > 131 r.connection.close() > > SpotifyException: http status: 405, code:-1 - https://api.spotify.com/v1/users/217plpxgwl26mxqkdifiyrndy?si=9cHjQNLQQOGzJQ6OuieIgQ/playlists: > error > Thanks in advance anyone who can help out!
kerem 2026-02-27 23:21:28 +03:00
  • closed this issue
  • added the
    bug
    label
Author
Owner

@C3theo commented on GitHub (Jun 17, 2019):

I believe the issue is stemming from changes in Spotify's Playlist API.

<!-- gh-comment-id:502810382 --> @C3theo commented on GitHub (Jun 17, 2019): I believe the issue is stemming from [changes in Spotify's Playlist API](https://developer.spotify.com/community/news/2018/06/12/changes-to-playlist-uris/).
Author
Owner

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

Looks like a duplicate, please read https://github.com/plamere/spotipy/issues/306#issuecomment-573900507

You shouldn't use client_credentials_manager with token, so this:

sp = spotipy.Spotify(auth = token, client_credentials_manager= client_credentials_manager)

should be:

sp = spotipy.Spotify(auth = token)
<!-- gh-comment-id:573906147 --> @stephanebruckert commented on GitHub (Jan 13, 2020): Looks like a duplicate, please read https://github.com/plamere/spotipy/issues/306#issuecomment-573900507 You shouldn't use `client_credentials_manager` with `token`, so this: sp = spotipy.Spotify(auth = token, client_credentials_manager= client_credentials_manager) should be: sp = spotipy.Spotify(auth = token)
Author
Owner

@dursab commented on GitHub (May 23, 2020):

Hello, I am also trying to edit a playlist with Spotipy and get the same issue as described above :
http status: 405, code:-1

Here is the code that I'm using:

import os
import spotipy
import spotipy.util as util


# Credentials
CLIENT_ID = 'XXXXX'
CLIENT_SECRET = 'XXXXX'
REDIRECT_URI = 'http://localhost:8888/callback'

# Scope
scope = 'user-library-read playlist-modify-public playlist-modify-private'

# User Id :
username = 'XXXXX'

# Erase cache and prompt for user permission
try :
    token = util.prompt_for_user_token(username, scope, client_id=CLIENT_ID, client_secret=CLIENT_SECRET, redirect_uri=REDIRECT_URI, cache_path=".cache-{username}")
    print ("SUCCESS!")
except:
    os.remove(f".cache-{username}")
    token = util.prompt_for_user_token(username, scope, client_id=CLIENT_ID, client_secret=CLIENT_SECRET, redirect_uri=REDIRECT_URI, cache_path=".cache-{username}")

# Create the spotifyObject
sp = spotipy.Spotify(auth=token)

# Access to Playlists
playlists = sp.current_user_playlists()

def findThePlaylist(playlists):
    playlistID = ''
    for i, item in enumerate(playlists['items']):
        if item['name'] == '100 latest song liked':
            playlistID = item['id']
    return playlistID

playlistID = findThePlaylist(playlists)

def deleteAllTheSongFromThePlaylist(playlistID, username):
    playlistTracks = sp.playlist_tracks(playlistID, fields='items.track')
    for item in playlistTracks['items']:
        trackID = item['track']['uri']
        sp.user_playlist_remove_all_occurrences_of_tracks(username, playlistID, trackID)

delete = deleteAllTheSongFromThePlaylist(playlistID, username)

and here is the error message I receive:

HTTP Error for DELETE to https://api.spotify.com/v1/users/.../playlists/.../tracks returned 405 due to error
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/spotipy/client.py", line 172, in _internal_call
    response.raise_for_status()
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/requests/models.py", line 941, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 405 Client Error: Method Not Allowed for url: https://api.spotify.com/v1/users/.../playlists/.../tracks

All the process for the credentials seemed to work fine cause the all script is working until the very last line above :

sp.user_playlist_remove_all_occurrences_of_tracks(username, playlistID, trackID)

So it seems that I can access everything but just not interact with it... could it be an issue link to the Authorization Flows? What I understand is that the Authorization Code is giving full access, is it what the prompt_for_user_token is doing?

I can see some similar issues but I couldn't find a way to make it works when following the indications given...

I believe that I'm using the Spotipy version 2.12.0 and python 3.8

Thanks in advance for anyone help!

<!-- gh-comment-id:632983567 --> @dursab commented on GitHub (May 23, 2020): Hello, I am also trying to edit a playlist with Spotipy and get the same issue as described above : **http status: 405, code:-1** Here is the code that I'm using: ``` import os import spotipy import spotipy.util as util # Credentials CLIENT_ID = 'XXXXX' CLIENT_SECRET = 'XXXXX' REDIRECT_URI = 'http://localhost:8888/callback' # Scope scope = 'user-library-read playlist-modify-public playlist-modify-private' # User Id : username = 'XXXXX' # Erase cache and prompt for user permission try : token = util.prompt_for_user_token(username, scope, client_id=CLIENT_ID, client_secret=CLIENT_SECRET, redirect_uri=REDIRECT_URI, cache_path=".cache-{username}") print ("SUCCESS!") except: os.remove(f".cache-{username}") token = util.prompt_for_user_token(username, scope, client_id=CLIENT_ID, client_secret=CLIENT_SECRET, redirect_uri=REDIRECT_URI, cache_path=".cache-{username}") # Create the spotifyObject sp = spotipy.Spotify(auth=token) # Access to Playlists playlists = sp.current_user_playlists() def findThePlaylist(playlists): playlistID = '' for i, item in enumerate(playlists['items']): if item['name'] == '100 latest song liked': playlistID = item['id'] return playlistID playlistID = findThePlaylist(playlists) def deleteAllTheSongFromThePlaylist(playlistID, username): playlistTracks = sp.playlist_tracks(playlistID, fields='items.track') for item in playlistTracks['items']: trackID = item['track']['uri'] sp.user_playlist_remove_all_occurrences_of_tracks(username, playlistID, trackID) delete = deleteAllTheSongFromThePlaylist(playlistID, username) ``` and here is the error message I receive: ``` HTTP Error for DELETE to https://api.spotify.com/v1/users/.../playlists/.../tracks returned 405 due to error Traceback (most recent call last): File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/spotipy/client.py", line 172, in _internal_call response.raise_for_status() File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/requests/models.py", line 941, in raise_for_status raise HTTPError(http_error_msg, response=self) requests.exceptions.HTTPError: 405 Client Error: Method Not Allowed for url: https://api.spotify.com/v1/users/.../playlists/.../tracks ``` All the process for the credentials seemed to work fine cause the all script is working until the very last line above : > sp.user_playlist_remove_all_occurrences_of_tracks(username, playlistID, trackID) So it seems that I can access everything but just not interact with it... could it be an issue link to the **Authorization Flows**? What I understand is that the **Authorization Code** is giving full access, is it what the **prompt_for_user_token** is doing? I can see some similar issues but I couldn't find a way to make it works when following the indications given... I believe that I'm using the Spotipy version 2.12.0 and python 3.8 Thanks in advance for anyone help!
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#225
No description provided.