我真的很感激你能帮上忙。我正在尝试使用Spotify API将专辑添加到用户库。我一直在为一个畸形的Json负载而苦苦挣扎,完全没有想法。
这是我目前所坐的简化版本
url = 'https://api.spotify.com/v1/me/albums'
payload = {'body': ['01kTgTBiZkCFY3ZH2hBH6u', '4sz6Fn4BYORRLIc1AvQwQx']}
headers = {'Authorization':'Bearer {}'.format(access_token), 'Content-Type':'application/json',}
response = requests.put(url,headers=headers, data=payload)
print(response.json())我收到的错误在json响应中:
{'error': {'status': 400, 'message': 'Malformed json payload'}}我已尝试按照下面的说明更改requests.put,但所有尝试都返回相同的错误
response = requests.put(url,headers=headers, json=payload)
response = requests.put(url,headers=headers, data=json.dumps(payload))
response = requests.put(url,headers=headers, json=json.dumps(payload))发布于 2020-04-12 02:44:56
07bYtmE3bPsLB6ZbmmFi8d:这个spotify账号是为专辑“Dancefloor Hits #1”准备的。我检查了我的spotify账号,发现它就在我的账号的相册里。下面是我运行它的代码。
import requests
url = "https://api.spotify.com/v1/me/albums"
payload = {"ids": "27cZdqrQiKt3IT00338dws"}
headers = {
'Content-Type': 'application/json',
'Authorization': 'Bearer %s' % (access_token) # paste your access token in here
}
''' you can use the same syntax as above but the key was that your ID of album had to be a **parameter** not ***data***.
To do that you use the params kwarg'''
response = requests.request("PUT", url, headers=headers, params = payload)
print(response.status_code) # should print out 200 when you run the code
# shows whether status was validhttps://stackoverflow.com/questions/61160753
复制相似问题