python - python 上的 Spotify API 授权错误
问题描述
我正在按照教程 创建 Spotify 播放列表。我已经遵循了每一步,但我遇到了授权问题。它应该返回一个包含歌曲的列表(稍后我会将它们输入到播放列表中),但我收到此错误:<class 'dict'>: {'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']}")
解决方案
您发送的令牌是什么?您是否仅将令牌存储在变量中token
?确保您以以下形式提供令牌Authorization: Bearer <YOURTOKEN>
。也许“承载者”这个词不见了?否则,您应该确保令牌实际上是有效的(请参阅文档)。
推荐阅读
- mysql - 如何在 MySQL 中“Unstack”一个表?
- reactjs - 如何重定向到个人资料?
- python - Vs 代码断点不止于 Python-Django API TestCase
- php - php代码从表1的值中删除值表2
- google-cloud-platform - Terraform 错误:在 gcp 上创建资源时,depends_on 属性不适用于 gcp 的 sql db 模块
- laravel - Laravel:api throttling (rate) 对于 spa 来说这是强制性的吗?
- ssl - Istio Gateway MUTUAL TLS 模式不工作
- c# - Linq获取两个列表的组合
- excel - 自动将 excel 文件嵌入到 powerpoint 幻灯片中的步骤
- python - 替换列中的重复值