У меня возникает эта ошибка, когда я пытаюсь создать плейлист, используя свою учетную запись. Когда я пытаюсь запустить код с помощью команды python3 Spotifyv2.py {имя_пользователя, выдает следующую ошибку:
HTTP Error for POST to https://api.spotify.com/v1/users/test/playlists with Params: {} returned 403 due to You cannot create a playlist for another user
Traceback (most recent call last):
File "/home/joachim/Jarvis/venv/lib/python3.12/site-packages/spotipy/client.py", line 271, in _internal_call
response.raise_for_status()
File "/home/joachim/Jarvis/venv/lib/python3.12/site-packages/requests/models.py", line 1026, in raise_for_status
raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 403 Client Error: Forbidden for url: https://api.spotify.com/v1/users/test/playlists
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/joachim/Jarvis/spotifyv2.py", line 33, in
playlist=sp.user_playlist_create('test',name=playlistname, public=False)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/joachim/Jarvis/venv/lib/python3.12/site-packages/spotipy/client.py", line 872, in user_playlist_create
return self._post(f"users/{user}/playlists", payload=data)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/joachim/Jarvis/venv/lib/python3.12/site-packages/spotipy/client.py", line 326, in _post
return self._internal_call("POST", url, payload, kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/joachim/Jarvis/venv/lib/python3.12/site-packages/spotipy/client.py", line 291, in _internal_call
raise SpotifyException(
spotipy.exceptions.SpotifyException: http status: 403, code: -1 - https://api.spotify.com/v1/users/test/playlists:
You cannot create a playlist for another user, reason: None
Это мой код:
import pprint
import sys
import spotipy # la librairie pour manipuler l'api spotify
import spotipy.util as util
import simplejson as json #pour manipuler les réponses json
import time #pour créer une playlist horodatée
from datetime import datetime
from random import shuffle #pour attribuer un classement aléatoire aux morceaux
username="00000"
clientId= "0000"
clientSecret="0000"
scope = 'playlist-modify-public playlist-modify-private'
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=clientId,client_secret=clientSecret,redirect_uri='http://127.0.0.1:8888/callback')
search="quicksand"
timestr = time.strftime("%Y%m%d")
playlistname=timestr+"_related_"+search
if token:
sp = spotipy.Spotify(auth=token)
sp.trace = False
# Création de la playlist
playlist=sp.user_playlist_create('test',name=playlistname, public=False)
playlist_id= str(playlist['id'])
else:
print("Can't get token for", username)