Spotipy:不允许用户创建播放列表方法

2024-04-25 09:03:40 发布

您现在位置:Python中文网/ 问答频道 /正文

使用spotipy库,我试图创建一个播放列表。但是,我的url不允许使用用户\u create\u playlist方法。下面是我的代码的一部分,展示了我如何验证我的应用程序以及我使用什么来运行该方法的示例:

username = 'my-username'
token = util.prompt_for_user_token(username = username,
     scope = 'playlist-modify-public'
     client_id='my-spotify-client-id', 
     client_secret='my-spotify-client-secret-id', 
     redirect_uri='https://developer.spotify.com/')
     spotifyObject = spotipy.Spotify(auth=token)
playlist_name = "Test Playlist"
playlist_description = "This is a test playlist."
playlists = spotifyObject.user_playlist_create(username, playlist_name, 
playlist_description)
pprint.pprint(playlists)

你知道为什么我会收到下面的错误信息吗?你知道吗

Traceback (most recent call last):
File "C:\Users....\spotipy\client.py", line 121, in _internal_call
r.raise_for_status()
File "C:\Users....requests\models.py", line 935, 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/'username'/playlists

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "C:\Users....\SpotifyTest.py", line 108, in 
main()
File "C:\Users....\SpotifyTest.py", line 53, in main
playlists = spotifyObject.user_playlist_create(username, playlist_name, playlist_description)
File "C:\Users....\spotipy\client.py", line 415, in user_playlist_create
return self._post("users/%s/playlists" % (user,), payload=data)
File "C:\Users.....\spotipy\client.py", line 180, in _post
return self._internal_call('POST', url, payload, kwargs)
File "C:\Users....\spotipy\client.py", line 129, in _internal_call
-1, '%s:\n %s' % (r.url, 'error'), headers=r.headers)
spotipy.client.SpotifyException: http status: 405, code:-1 - https://api.spotify.com/v1/users/'username'/playlists:
error

Tags: inpyclienturlcreatelineusernamecall