Appoma
Appoma

Reputation: 11

Spotify API Curl request to Python Request

I'm currently trying to request an access token through the spotify API and am having trouble because the way the guide requests from the token endpoint is as such:

curl -H "Authorization: Basic ZjM...zE=" -d grant_type=authorization_code -d code=MQCbtKe...44KN -d redirect_uri=https%3A%2F%2Fwww.foo.com%2Fauth https://accounts.spotify.com/api/token

I'm instead trying to implement this solely in Python and am confused on how I would make this request using the requests library in Python. I've outlined what I think the request should look like:

r = requests.post("https://accounts.spotify.com/api/token", data = {}, auth = (client_id, client_secret))

But I am a little lost, any help would be appreciated!

Upvotes: 1

Views: 307

Answers (1)

Noé
Noé

Reputation: 325

You can visit this website. Your curl command looks like that in python :

import requests

headers = {
    'Authorization': 'Basic ZjM...zE=',
}

data = {
  'grant_type': 'authorization_code',
  'code': 'MQCbtKe...44KN',
  'redirect_uri': 'https://www.your_address.com/auth'
}

response = requests.post('https://accounts.spotify.com/api/token', headers=headers, data=data)

Upvotes: 1

Related Questions