Spotify Search API Authorization Error when using with Python
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page