【问题标题】:Error with Spotify API authorization on pythonpython 上的 Spotify API 授权错误
【发布时间】:2021-03-08 05:23:08
【问题描述】:

我正在关注 tutorial 以创建 Spotify 播放列表。我已经遵循了每一步,但我遇到了授权问题。 它应该返回一个包含歌曲的列表(稍后我会将它们输入到播放列表中),但我收到此错误:: {'error': {'status': 400, 'message': 'Only valid支持承载认证'}}

这是我的代码:

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

【问题讨论】:

    标签: python json api spotify


    【解决方案1】:

    您发送的令牌是什么?您是否仅将令牌存储在变量token 中?确保以以下形式提供令牌 Authorization: Bearer <YOURTOKEN>。也许“承载者”这个词不见了?否则,您应该确保令牌实际上是有效的(请参阅文档)。

    【讨论】:

      猜你喜欢
      • 2018-08-12
      • 2017-12-23
      • 2018-05-21
      • 2020-07-13
      • 1970-01-01
      • 1970-01-01
      • 2018-09-22
      • 2021-07-04
      • 2017-12-29
      相关资源
      最近更新 更多