首页 > 解决方案 > Spotipy - 用于 Python 无效推荐请求的 Spotify API

问题描述

提出建议请求时,例如:

recommend = sp.recommendations(target_energy = 0.5)

我得到错误:

Traceback (most recent call last):
File "script.py", line 62, in 
recommend = sp.recommendations(target_energy = 0.5)
File "/usr/local/lib/python2.7/dist-packages/spotipy/client.py", line 804, in recommendations
return self._get('recommendations', **params)
File "/usr/local/lib/python2.7/dist-packages/spotipy/client.py", line 146, in _get
return self._internal_call('GET', url, payload, kwargs)
File "/usr/local/lib/python2.7/dist-packages/spotipy/client.py", line 124, in _internal_call
headers=r.headers)
spotipy.client.SpotifyException: http status: 400, code:-1 - https://api.spotify.com/v1/recommendations?target_energy=0.5&limit=20:
invalid request

为什么这给出了无效请求的任何特殊原因?我尝试咨询文档,但找不到解释

标签: pythonspotipy

解决方案


您没有为您的recommendations通话提供正确的参数。您还需要提供或参数seed_artists,否则 API 很难找到建议。seed_genresseed_tracks

官方文档是一个很好的资源。

这是使用 cURL 的示例调用

curl -X GET "https://api.spotify.com/v1/recommendations?seed_artists=4NHQUGzhtTLFvgF5SZesLK&seed_tracks=0c6xIDDpzE81m2q797ordA&min_energy=0.4&min_popularity=50&market=US" -H "Authorization: Bearer {your access token}"

推荐阅读