Matthew Justin
Matthew Justin

Reputation: 83

Spotipy: AttributeError: 'list' object has no attribute 'split'

I'm somewhat new to python - just a couple of months - but I'm trying to wrap my head around an AttributeError I keep getting when using Spotipy to grab some audio features.

When I run this:

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]))

I get this:

(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'

Am I right in thinking that the audio_features function in SpotiPy has a split function that isn't liking my list, because there isn't a list of strings like "'track' : '5v4GgrXPMghOnBBLmveLac'"?

Any help at all would be greatly appreciated!

Matthew

Upvotes: 0

Views: 564

Answers (1)

Shreyas Sreenivas
Shreyas Sreenivas

Reputation: 351

Try print(spotify.audio_features(tracks=bb_songs)) Remove the square brackets

Instead of print(spotify.audio_features(tracks=[bb_songs]))

Wrapping your list around a set of square brackets creates a list with one element in it which is your list. The function tries tries iterating over the list elements, performing a split function on each of them. However, since you're passing a list of lists, the function returns an error.

Upvotes: 2

Related Questions