【问题标题】:Spotipy: AttributeError: 'list' object has no attribute 'split'Spotipy:AttributeError:“list”对象没有属性“split”
【发布时间】:2020-06-10 03:02:46
【问题描述】:

我对 python 有点陌生——才几个月——但我正试图解决我在使用 Spotipy 获取一些音频功能时不断遇到的 AttributeError 问题。

当我运行这个时:

bb_songs = ['24ySl2hOPGCDcxBxFIqWBu', '5v4GgrXPMghOnBBLmveLac', etc...  # a list of Spotify song IDs
spotify = spotipy.Spotify(client_credentials_manager=SpotifyClientCredentials())
credentials = spotipy.oauth2.SpotifyClientCredentials()
print(spotify.audio_features(tracks=[bb_songs]))

我明白了:

(base) Matthews-MBP-2:spotipy MattJust$ python3 erase.py
Traceback (most recent call last):
  File "erase.py", line 20, in <module>
    print(spotify.audio_features(tracks=[bb_songs]))
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/spotipy/client.py", line 1243, in audio_features
    tlist = [self._get_id("track", t) for t in tracks]
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/spotipy/client.py", line 1243, in <listcomp>
    tlist = [self._get_id("track", t) for t in tracks]
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/spotipy/client.py", line 1462, in _get_id
    fields = id.split(":")
AttributeError: 'list' object has no attribute 'split'

我是否认为 SpotiPy 中的 audio_features 函数有一个不喜欢我的列表的拆分函数,因为没有像 "'track' : '5v4GgrXPMghOnBBLmveLac'" 这样的字符串列表?

任何帮助将不胜感激!

马修

【问题讨论】:

    标签: python spotify spotipy


    【解决方案1】:

    试试 print(spotify.audio_features(tracks=bb_songs))去掉方括号

    而不是 print(spotify.audio_features(tracks=[bb_songs]))

    将您的列表包裹在一组方括号中会创建一个列表,其中包含一个元素,即您的列表。该函数尝试迭代列表元素,对每个元素执行拆分函数。但是,由于您传递的是列表列表,因此该函数会返回错误。

    【讨论】:

    • 做到了,你的解释肯定有帮助!非常感谢,Shreyas!
    • 没问题:)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-01-18
    • 1970-01-01
    • 2019-10-21
    • 1970-01-01
    • 2021-04-05
    • 2014-05-15
    • 2017-07-02
    相关资源
    最近更新 更多