bacjist
bacjist

Reputation: 23

Error with Spotify API authorization on python

I`m following a tutorial to create a Spotify playlist. I've followe every step but I'm having a problem with authorization. It should return a list with songs (later i will enter them on a playlist), but i get this error: <class 'dict'>: {'error': {'status': 400, 'message': 'Only valid bearer authentication supported'}}

This is the code i have:

import requests

url = "https://api.spotify.com/v1/recommendations?"
token = "I WILL CREATE A TOKEN GETTER"

#Filtros
limit = input("How many songs? ")
market = "ES"
seed_genres = input("Select the genres: ")
target_energy = int(input("From 0 to 10 how energetic do you want your playlist? "))/10

#Contactar con Spotify
query = f"{url}limit={limit}&market={market}&seed_genres={seed_genres}&target_energy={target_energy}"

response = requests.get(query,
                       headers = {"Content-Type":"application/json",
                                  "Authorization": f'{token}'})
json_response = response.json()

for i in json_response['tracks']:
            uris.append(i)
            print(f"\"{i['name']}\" by {i['artists'][0]['name']}")

Upvotes: 1

Views: 153

Answers (1)

zunkelty
zunkelty

Reputation: 317

What is the token you are sending? Are you storing just the token in the variable token? Make sure that you provide the token in the following form Authorization: Bearer <YOURTOKEN>. Maybe the word „Bearer“ is missing? Otherwise you should make sure that the token is actually a valid one (see the docs).

Upvotes: 1

Related Questions