[GH-ISSUE #764] playlist_is_following not handling user_ids correctly #464

Closed
opened 2026-02-27 23:22:47 +03:00 by kerem · 2 comments
Owner

Originally created by @CodeWriter194 on GitHub (Jan 3, 2022).
Original GitHub issue: https://github.com/spotipy-dev/spotipy/issues/764

Describe the bug
Attempting to determine if a given user follows a specific playlist returns an error stating that too many IDs were given, regardless of how many IDs are provided. 'playlist_is_following' appears to comma separate any value submitted for "USER_IDS", resulting in each character of a user ID being treated as a user ID on its own.

Your code
client_id = 'REDACTED'
client_secret = 'REDACTED'
client_credentials_manager = SpotifyClientCredentials(client_id=client_id, client_secret=client_secret)
sp = spotipy.Spotify(client_credentials_manager=client_credentials_manager)

barUserID = 'REDACTED'
fooUserID = 'REDACTED'

fooPlaylists = sp.user_playlists(fooUserID)
for i, item in enumerate(fooPlaylists['items']):
fooPlaylistIDs[i] = item['id']
print(sp.user_playlist_is_following(fooUserID,fooPlaylistIDs[i],barUserID))

Expected behavior
I expect to have 'True' or 'False' be returned when using method 'playlist_is_following'.

Output
Paste and format errors (with complete stacktrace) or logs. Make sure to remove sensitive information.

HTTP Error for GET to https://api.spotify.com/v1/playlists/VALID_PLAYLIST_ID/followers/contains?ids=c,3,a,h,y,2,4,5,p,8,v,u,5,e,p,6,d,n,8,e,d,f,f,x,s returned 400 due to Too many ids given
Traceback (most recent call last):
  File "\AppData\Local\Programs\Python\Python39\lib\site-packages\spotipy\client.py", line 245, in _internal_call
    response.raise_for_status()
  File "\AppData\Local\Programs\Python\Python39\lib\site-packages\requests\models.py", line 943, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 400 Client Error: Bad Request for url: https://api.spotify.com/v1/playlists/VALID_PLAYLIST_ID/followers/contains?ids=c,3,a,h,y,2,4,5,p,8,v,u,5,e,p,6,d,n,8,e,d,f,f,x,s

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "script2.py", line 47, in <module>
    print(sp.user_playlist_is_following(fooUserID,fooPlaylistIDs[i],barUserID))
  File "\AppData\Local\Programs\Python\Python39\lib\site-packages\spotipy\client.py", line 969, in user_playlist_is_following
    return self.playlist_is_following(playlist_id, user_ids)
  File "\AppData\Local\Programs\Python\Python39\lib\site-packages\spotipy\client.py", line 1153, in playlist_is_following
    return self._get(
  File "\AppData\Local\Programs\Python\Python39\lib\site-packages\spotipy\client.py", line 291, in _get
    return self._internal_call("GET", url, payload, kwargs)
  File "\AppData\Local\Programs\Python\Python39\lib\site-packages\spotipy\client.py", line 261, in _internal_call
    raise SpotifyException(
spotipy.exceptions.SpotifyException: http status: 400, code:-1 - https://api.spotify.com/v1/playlists/VALID_PLAYLIST_ID/followers/contains?ids=c,3,a,h,y,2,4,5,p,8,v,u,5,e,p,6,d,n,8,e,d,f,f,x,s:
 Too many ids given, reason: None

Environment:

  • Windows 10
  • Python 3.9.6
  • spotipy version [e.g. 2.18.0]
  • Notepad++

Additional context
It seems that 'user_playlist_is_following' is a deprecated method, but changing to 'playlist_is_following' does not change the results.
Changing the below code in 'client.py' does seem to fix the issue, though.


    def playlist_is_following(
        self, playlist_id, user_ids
    ):
        """
        Check to see if the given users are following the given playlist

        Parameters:
            - playlist_id - the id of the playlist
            - user_ids - the ids of the users that you want to check to see
                if they follow the playlist. Maximum: 5 ids.

        """
        endpoint = "playlists/{}/followers/contains?ids={}"
        return self._get(
-           endpoint.format(playlist_id, ",".join(user_ids))
+           endpoint.format(playlist_id, user_ids)
        )
Originally created by @CodeWriter194 on GitHub (Jan 3, 2022). Original GitHub issue: https://github.com/spotipy-dev/spotipy/issues/764 **Describe the bug** Attempting to determine if a given user follows a specific playlist returns an error stating that too many IDs were given, regardless of how many IDs are provided. 'playlist_is_following' appears to comma separate any value submitted for "USER_IDS", resulting in each character of a user ID being treated as a user ID on its own. **Your code** client_id = 'REDACTED' client_secret = 'REDACTED' client_credentials_manager = SpotifyClientCredentials(client_id=client_id, client_secret=client_secret) sp = spotipy.Spotify(client_credentials_manager=client_credentials_manager) barUserID = 'REDACTED' fooUserID = 'REDACTED' fooPlaylists = sp.user_playlists(fooUserID) for i, item in enumerate(fooPlaylists['items']): fooPlaylistIDs[i] = item['id'] print(sp.user_playlist_is_following(fooUserID,fooPlaylistIDs[i],barUserID)) **Expected behavior** I expect to have 'True' or 'False' be returned when using method 'playlist_is_following'. **Output** Paste and format errors (with complete stacktrace) or logs. Make sure to remove sensitive information. ``` HTTP Error for GET to https://api.spotify.com/v1/playlists/VALID_PLAYLIST_ID/followers/contains?ids=c,3,a,h,y,2,4,5,p,8,v,u,5,e,p,6,d,n,8,e,d,f,f,x,s returned 400 due to Too many ids given Traceback (most recent call last): File "\AppData\Local\Programs\Python\Python39\lib\site-packages\spotipy\client.py", line 245, in _internal_call response.raise_for_status() File "\AppData\Local\Programs\Python\Python39\lib\site-packages\requests\models.py", line 943, in raise_for_status raise HTTPError(http_error_msg, response=self) requests.exceptions.HTTPError: 400 Client Error: Bad Request for url: https://api.spotify.com/v1/playlists/VALID_PLAYLIST_ID/followers/contains?ids=c,3,a,h,y,2,4,5,p,8,v,u,5,e,p,6,d,n,8,e,d,f,f,x,s During handling of the above exception, another exception occurred: Traceback (most recent call last): File "script2.py", line 47, in <module> print(sp.user_playlist_is_following(fooUserID,fooPlaylistIDs[i],barUserID)) File "\AppData\Local\Programs\Python\Python39\lib\site-packages\spotipy\client.py", line 969, in user_playlist_is_following return self.playlist_is_following(playlist_id, user_ids) File "\AppData\Local\Programs\Python\Python39\lib\site-packages\spotipy\client.py", line 1153, in playlist_is_following return self._get( File "\AppData\Local\Programs\Python\Python39\lib\site-packages\spotipy\client.py", line 291, in _get return self._internal_call("GET", url, payload, kwargs) File "\AppData\Local\Programs\Python\Python39\lib\site-packages\spotipy\client.py", line 261, in _internal_call raise SpotifyException( spotipy.exceptions.SpotifyException: http status: 400, code:-1 - https://api.spotify.com/v1/playlists/VALID_PLAYLIST_ID/followers/contains?ids=c,3,a,h,y,2,4,5,p,8,v,u,5,e,p,6,d,n,8,e,d,f,f,x,s: Too many ids given, reason: None ``` **Environment:** - Windows 10 - Python 3.9.6 - spotipy version [e.g. 2.18.0] - Notepad++ **Additional context** It seems that 'user_playlist_is_following' is a deprecated method, but changing to 'playlist_is_following' does not change the results. Changing the below code in 'client.py' does seem to fix the issue, though. ``` def playlist_is_following( self, playlist_id, user_ids ): """ Check to see if the given users are following the given playlist Parameters: - playlist_id - the id of the playlist - user_ids - the ids of the users that you want to check to see if they follow the playlist. Maximum: 5 ids. """ endpoint = "playlists/{}/followers/contains?ids={}" return self._get( - endpoint.format(playlist_id, ",".join(user_ids)) + endpoint.format(playlist_id, user_ids) ) ```
kerem 2026-02-27 23:22:47 +03:00
  • closed this issue
  • added the
    bug
    label
Author
Owner

@stephanebruckert commented on GitHub (Jan 3, 2022):

user_ids needs to be passed as a list

<!-- gh-comment-id:1003834807 --> @stephanebruckert commented on GitHub (Jan 3, 2022): `user_ids` needs to be passed as a list
Author
Owner

@CodeWriter194 commented on GitHub (Jan 3, 2022):

That's a bit embarrassing - thanks!

<!-- gh-comment-id:1003835272 --> @CodeWriter194 commented on GitHub (Jan 3, 2022): That's a bit embarrassing - thanks!
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/spotipy#464
No description provided.