【发布时间】:2022-01-21 07:09:42
【问题描述】:
我找到了一个笔记本,但我卡在了这一点上[10]:
import pandas as pd
使用 API 循环遍历轨道 URI 和拉取艺术家 URI, 然后使用艺术家 URI 提取与该艺术家关联的流派 将所有这些存储在字典中
for t_uri in track_uris:
dict_genre[t_uri] = {'artist_uri': "", "genres":[]}
r = requests.get(BASE_URL + 'tracks/' + t_uri, headers=headers)
r = r.json()
a_uri = r['artists'][0]['uri'].split(':')[2]
dict_genre[t_uri]['artist_uri'] = a_uri
s = requests.get(BASE_URL + 'artists/' + a_uri, headers=headers)
s = s.json()
dict_genre[t_uri]['genres'] = s['genres']
KeyError
Traceback (most recent call last) <ipython-input-43-3c5b75bf03e3> in <module>()
14 r = requests.get(BASE_URL + 'tracks/' + t_uri, headers=headers)
15 r = r.json()
---> 16 a_uri = r['artists'][0]['uri'].split(':')[2]*
KeyError: 'artists'
来源:
【问题讨论】:
-
试试
print(r)看看数据包含什么。 -
print(r) inside for
output: {'error': {'status': 429, 'message': 'API rate limit exceeded'}}print(r) outside foroutput: {'error': {'status': 429, 'message': 'API rate limit exceeded'}} {'album': {'album_type': 'single', 'artists': [{'external_urls': {'spotify': *URL Links after this* -
“超出速率限制”似乎是显而易见的问题。
-
@Barmar 谢谢,非常感谢您的帮助
-
请澄清您的具体问题或提供更多详细信息以准确突出您的需求。正如目前所写的那样,很难准确地说出你在问什么。
标签: python pandas dataframe spotify