【问题标题】:TypeError: Getting multiple Artist IDs from the Spotify APITypeError:从 Spotify API 获取多个艺术家 ID
【发布时间】:2020-06-27 12:09:38
【问题描述】:

我正在尝试使用 Spotipy 和艺术家姓名从 Spotify API 获取多个艺术家 ID 的列表。 Spotify 文档说您一次最多可以抓取 50 个。如果我试试这个:

names = ["push baby", "rkls", "seiji oda", "slowthai"]
results = spotify.search(q='artist:' + names, type='artist')

...我收到此错误:

TypeError: can only concatenate str (not "list") to str

当我尝试这个时:

names = ["push baby", "rkls", "seiji oda", "slowthai"]
results = spotify.search(q=['artist:' + f"{x}" for x in names], type='artist')

...它只给了我列表中第一项的 ID,“push baby”。

如果我试试这个:

names = ["push baby", "rkls", "seiji oda", "slowthai"]
results = for x in names: spotify.search(q=['artist:' + f"{x}"], type='artist')

...它给了我一个无效的语法错误。

对我应该如何写这篇文章有什么建议吗?

谢谢! 马修

编辑:这是我使用的更完整的代码,有四种变体,但都不起作用:

names = ["push baby", "rkls", "seiji oda", "slowthai"]

# results = spotify.search(q='artist:' + names[2], limit=50, type='artist')
# results = spotify.search(q=['artist:' + f"{x}" for x in names], limit=50, type='artist')
# results = for x in names: spotify.search(q=['artist:' + f"{x}"], limit=50, type='artist')
results = spotify.search(q=["push baby", "rkls", "seiji oda", "slowthai"], limit=50, type='artist')

items = results['artists']['items']

artist = items[0]
print(artist['name'], artist['id'])

【问题讨论】:

  • 我倾向于认为第一个应该按原样工作。如果我使用 q=['artist:' + f"{x}" for x in names[0]] 它成功地返回 ID 只是该列表的第一项,“push baby”。这让我想到,如果我把那个 [0] 去掉,它应该适用于整个列表,但那不会发生。

标签: typeerror spotify spotipy


【解决方案1】:

查看 Spotify 文档,您似乎可以指定最多 50 个退货,但只能指定一个请求,这意味着 1200 位艺术家必须一一完成。呵呵!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-05-11
    • 2020-10-17
    • 1970-01-01
    • 2020-06-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多