"spotipy.exceptions.SpotifyException: http status: 400, code:-1" 使用来自 spotipy 的 recommendations() 时 API

"spotipy.exceptions.SpotifyException: http status: 400, code:-1" when using recommendations() from spotipy API

我正在尝试使用 spotipy 构建一个程序,它将创建一个自定义的 spotify 播放列表。 我成功地使用 current_user_recently_played() 函数获得了三个列表,其中包含最近播放的流派、艺术家和曲目。根据这三个列表,我正在尝试使用 spotipy.client.Spotify.recommendations 以获得这三个参数的建议。 the func description from the spotipy documentation

这是代码:

 recommendations = spotify.recommendations(seed_artists=artists, seed_genres=genres, seed_tracks=tracks)

时间:

artists = ['5eAWCfyUhZtHHtBdNk56l1', '6mdiAmATAx73kdxrNrnlao', '0epOFNiUfyON9EYx7Tpr6V']   
tracks = ['31RTFPrB7wmYBhlkM2ILXG', '3nlGByvetDcS1uomAoiBmy', '55N8cxpE1QDoeaaNqUnoZ2']
genres = ['rock', 'metal', 'punk', 'grunge', 'pop']

当我运行代码时出现此错误:

HTTP Error for GET to https://api.spotify.com/v1/recommendations returned 400 due to invalid request
Traceback (most recent call last):
  File "C:\Users\itama\AppData\Local\Programs\Python\Python37-32\lib\site-packages\spotipy\client.py", line 172, in _internal_call
    response.raise_for_status()
  File "C:\Users\itama\AppData\Local\Programs\Python\Python37-32\lib\site-packages\requests\models.py", line 940, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 400 Client Error: Bad Request for url: https://api.spotify.com/v1/recommendations?limit=20&seed_artists=5eAWCfyUhZtHHtBdNk56l1%2C6mdiAmATAx73kdxrNrnlao%2C0epOFNiUfyON9EYx7Tpr6V%2C7oPftvlwr6VrsViSDV7fJY&seed_genres=rock%2Cmetal%2Cpunk%2Cgrunge&seed_tracks=31RTFPrB7wmYBhlkM2ILXG%2C3nlGByvetDcS1uomAoiBmy%2C55N8cxpE1QDoeaaNqUnoZ2%2C3LRJbFT9rKoKv4aW7PuBJC

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\itama\Desktop\recommendation_playlist.py", line 50, in <module>
    print(spotify.recommendations(seed_artists=artists[:4], seed_genres=genres[:4], seed_tracks=tracks[:4],))
  File "C:\Users\itama\AppData\Local\Programs\Python\Python37-32\lib\site-packages\spotipy\client.py", line 1219, in recommendations
    return self._get("recommendations", **params)
  File "C:\Users\itama\AppData\Local\Programs\Python\Python37-32\lib\site-packages\spotipy\client.py", line 207, in _get
    return self._internal_call("GET", url, payload, kwargs)
  File "C:\Users\itama\AppData\Local\Programs\Python\Python37-32\lib\site-packages\spotipy\client.py", line 187, in _internal_call
    headers=response.headers,
spotipy.exceptions.SpotifyException: http status: 400, code:-1 - https://api.spotify.com/v1/recommendations?limit=20&seed_artists=5eAWCfyUhZtHHtBdNk56l1%2C6mdiAmATAx73kdxrNrnlao%2C0epOFNiUfyON9EYx7Tpr6V%2C7oPftvlwr6VrsViSDV7fJY&seed_genres=rock%2Cmetal%2Cpunk%2Cgrunge&seed_tracks=31RTFPrB7wmYBhlkM2ILXG%2C3nlGByvetDcS1uomAoiBmy%2C55N8cxpE1QDoeaaNqUnoZ2%2C3LRJbFT9rKoKv4aW7PuBJC:
 invalid request

有什么办法解决这个问题吗?谢谢

明白了...您不能使用超过五个种子。