Использование Python, я пытаюсь сделать POST вызов к API Spotify, следуя инструкциям по пункту Клиентские Credentials Flow по ссылке https://developer.spotify.com/web-api/authorization-guide/#client_credentials_flow и это код, который я придумал. Тем не менее, я получаю ответ [415], когда я его запускаю. Может ли кто-нибудь сказать мне, что не так?Python: Spotify API Почтовый вызов?
import pprint
import requests
import urllib2
import json
import base64
client_id='b040c4e03217489aa647c055265d0ac'
client_secret='2c2928bb7d3e43278424002d2e8bda46b'
authorization_param='Basic ' + base64.standard_b64encode(client_id + ':' + client_secret)
grant_type='client_credentials'
#Request based on Client Credentials Flow from https://developer.spotify.com/web-api/authorization-guide/
#Header must be a base 64 encoded string that contains the client ID and client secret key.
#The field must have the format: Authorization: Basic <base64 encoded client_id:client_secret>
header_params={'Authorization' : authorization_param}
#Request body parameter: grant_type Value: Required. Set it to client_credentials
body_params = {'grant_type' : grant_type}
url='https://accounts.spotify.com/api/token'
response=requests.post(url, header_params, body_params) # POST request takes both headers and body parameters
print response
состояние 400 является то, что вы хотите? – Ajay
нет ... 400 - плохая просьба. Мне нужно 200 –
'header_params = {'Авторизация': authorization_param, 'grant_type': grant_type}' 'response = requests.post (url, header_params)' попробуйте это – Ajay