Spotify Web API 未检测到 POST 请求的正文
Spotify Web API not detecting body of POST request
我目前正在开发一个应用程序,它的一个功能是可以将歌曲添加到用户的队列中。为此,我正在使用 Spotify API,这是我的代码:
async def request():
...
uri = "spotify:track:5QO79kh1waicV47BqGRL3g" # temporary, can change later on
header = {'Content-Type': 'application/x-www-form-urlencoded',
'Authorization': "{} {}".format(TOKEN_TYPE, ACCESS_TOKEN)}
data = {'uri': uri}
resp = requests.post(url="https://api.spotify.com/v1/me/player/queue", data=data, headers=header)
...
我尝试了很多方法,但似乎无法理解为什么我会收到错误 400(错误 400:缺少必需的参数 uri)。
所以您正在使用的 endpoint 的 Spotify API 建议将所需的 uri 参数作为 url 的一部分传递,而不是作为 [=11] =]对象。
您可以尝试将您的 uri 添加到 url 的末尾,而不是 data = {'uri': uri}
:
resp = requests.post(url="https://api.spotify.com/v1/me/player/queue?uri=?uri=spotify%3Atrack%3A5QO79kh1waicV47BqGRL3g", headers=header)
我还建议使用 postman 或 insomnia 等软件来处理您发送的请求。
我目前正在开发一个应用程序,它的一个功能是可以将歌曲添加到用户的队列中。为此,我正在使用 Spotify API,这是我的代码:
async def request():
...
uri = "spotify:track:5QO79kh1waicV47BqGRL3g" # temporary, can change later on
header = {'Content-Type': 'application/x-www-form-urlencoded',
'Authorization': "{} {}".format(TOKEN_TYPE, ACCESS_TOKEN)}
data = {'uri': uri}
resp = requests.post(url="https://api.spotify.com/v1/me/player/queue", data=data, headers=header)
...
我尝试了很多方法,但似乎无法理解为什么我会收到错误 400(错误 400:缺少必需的参数 uri)。
所以您正在使用的 endpoint 的 Spotify API 建议将所需的 uri 参数作为 url 的一部分传递,而不是作为 [=11] =]对象。
您可以尝试将您的 uri 添加到 url 的末尾,而不是 data = {'uri': uri}
:
resp = requests.post(url="https://api.spotify.com/v1/me/player/queue?uri=?uri=spotify%3Atrack%3A5QO79kh1waicV47BqGRL3g", headers=header)
我还建议使用 postman 或 insomnia 等软件来处理您发送的请求。