I am trying to get artist information using the Spotify API. Authorization key works with Spotify console. but when I am running my python file in my machine it showing error only valid bearer authentication supported.
import requests
import json
import pprint
endpoint_url = "https://api.spotify.com/v1/search?"
# OUR FILTERS
query = "john"
typ = "artist"
limit = 1
offset = 1
token="BQCjNYC2q_m1e_JAQgttZ3F-1CW1mnai9E2psfLbwY15kbtd7u2sjuPiF7ld8hbUshPJGLlBK3kLDIebgtk_K3bDrggExZDJ1zEMb8WVvV1DEx2rUK2youoeqT1rmXDT99P04rs8O0ie"
query = f'{endpoint_url}q={query}&type={typ}&limit={limit}&offset={offset}'
response = requests.get(query,
headers={"Content-Type": "application/json",
"Authorization": token})
json_response = response.json()
pprint.pprint(json_response)
Result:
{'error': {'message': 'Only valid bearer authentication supported',
'status': 400}}
You need to append 'Bearer' to the value of the Authorization header:
"Authorization": 'Bearer ' + token
edit:
As you are using Python 3.6 or further:
"Authorization": f'Bearer {token}'