我对 python 有点陌生——只有几个月——但我正在努力解决我在使用 Spotipy 获取一些音频功能时不断遇到的 AttributeError。当我运行这个:bb_songs = ['24ySl2hOPGCDcxBxFIqWBu', '5v4GgrXPMghOnBBLmveLac', etc... # a list of Spotify song IDsspotify = 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.pyTraceback (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'”这样的字符串列表?任何帮助都将不胜感激!
1 回答
MMTTMM
TA贡献1869条经验 获得超4个赞
尝试 print(spotify.audio_features(tracks=bb_songs))
删除方括号
代替 print(spotify.audio_features(tracks=[bb_songs]))
将您的列表包裹在一组方括号中会创建一个列表,其中包含一个元素,即您的列表。该函数尝试遍历列表元素,对每个元素执行拆分函数。但是,由于您传递的是一个列表列表,该函数会返回一个错误。
添加回答
举报
0/150
提交
取消