Announcements
The Spotify Community is in read-only mode while we move to a new platform. We expect to be back up and running October 6th. During this time you can read existing content but take no other actions. If you still need help, visit our Support Site or contact us.

Help Wizard

Step 1

NEXT STEP

Spotify Search API Authorization Error when using with Python

Spotify Search API Authorization Error when using with Python

Plan

Free

Country

India

Device

Web API

Operating System

Python

 

My Question or Issue

I'm trying to use Python Search API with Python using bearer token. When I'm trying the API on API docs page of spotify using generated bearer token, I'm getting search results, but when I'm trying to use the same token with Python Code, I'm getting bearer token authentication error(400).

 

Can anyone help me to understand, why I'm not able to use search API using Python Code?

 

Python Code:

```

from requests import post, get

headers = {
    'Authorization': f'''Basic <'base64-encoded-secret'>'''
    ,'Content-Type': 'application/x-www-form-urlencoded'
    }
data = {'grant_type':'client_credentials'}
response = post(url = url, headers = headers, data = data).json()

authorization_header = f'''{response.get('token_type')} {response.get('access_token')}'''
print(authorization_header)
search_data = {
    'q': f'''track: ishq sufiyana year: 2011'''
    ,'type': 'track'
}
search_header = {
    'Accept': 'application/json'
    ,'Content-Type': 'application/json'
    ,'Authorization': authorization_header
}

search_response = get(url=search_endpoint, headers=headers, params=search_data).json()
print(search_response)

```

Reply
0 Replies

Suggested posts

Let's introduce ourselves!

Hey there you,   Yeah, you! 😁   Welcome - we're glad you joined the Spotify Community!   While you here, let's have a fun game and get…

ModeratorStaff / Moderator/ 5 years ago  in Social & Random