python - 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
为什么这给出了无效请求的任何特殊原因?我尝试咨询文档,但找不到解释
解决方案
您没有为您的recommendations
通话提供正确的参数。您还需要提供或参数seed_artists
,否则 API 很难找到建议。seed_genres
seed_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}"
推荐阅读
- marklogic - Marklogic CPF 策略
- build - 如何在 Travis CI 中为 C++ 项目并行运行多个构建,每个构建都有单独的脚本?
- python - 如何查看 anaconda 是否已完美安装并运行?
- javascript - 经过一段时间后,可观察的运算符“做”某事
- git - GIT rebase 合并分支
- django - 添加新字段时,Django 迁移失败
- android - Android Studio 调试器窗口中的数字是什么意思?
- qt - 如何从 QT 中的 txt 文件加载 500MB 数据
- zabbix - ZabbixAPI,从每个主机的特定字段中检索信息
- perl - Perl 数据转储器说明符说明