Spotipy:User_create_playlist - 不允许使用url的方法

时间:2018-04-08 03:30:03

标签: python spotify

使用spotipy库,我试图创建一个播放列表。但是,我的url不允许使用user_create_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

0 个答案:

没有答案