1

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']}")

1 Answer 1

1

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).

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.