spotifyspotipy

Spotipy current_user_playlists() does not execute the request


I have been coding a little web app using spotipy. Everything was working normally until 2 days ago it stopped executing the sp.current_user_playlists() function. The request is being build and sent by spotipy, but it seems to never get an answer. Other functions such as playlist_items() work perfectly fine. If I try that API endpoint via the spotify documentation, I also get the expected result. There is no error or anything for that matter, the site just keeps loading and the server appears to be doing nothing.

I am sure that I have all the required scopes for this endpoint, since it did work a couple of days ago.

SpotifyOAuth(client_id=client_id,
                    client_secret=client_secret,
                    redirect_uri=url_for('redirect_page', _external=True),
                    scope='user-read-playback-state user-modify-playback-state user-read-currently-playing '
                          'playlist-read-collaborative, playlist-read-private, user-library-read, '
                          'playlist-modify-private, playlist-modify-public'
                    )

If anyone has an idea what the issue could be, I would be very thankful!


Solution

  • What I think has happened is that the limitations to the Spotify API, which came in two days ago, have caused an issue in my program (and possibly yours), causing it to constantly retry an API call. (Probably to query my Spotify-created playlists, which are now no longer available.). If I look at my dashboard, I see almost 5k calls to the playlist API yesterday. I think the issue is that current_user_playlists now returns a null entry for any playlist that is now blocked through the API, rather than omitting them, and I wasn't handling that: (This seems to be in violation of the documented behaviour of the API)

    {
      "href": "https://api.spotify.com/v1/users/murraypaul/playlists?offset=0&limit=50&locale=en-GB,en-US;q%3D0.9,en;q%3D0.8",
      "limit": 50,
      "next": "https://api.spotify.com/v1/users/murraypaul/playlists?offset=50&limit=50&locale=en-GB,en-US;q%3D0.9,en;q%3D0.8",
      "offset": 0,
      "previous": null,
      "total": 246,
      "items": [
        {
          "collaborative": false,
          "description": "",
          [..]
        },
        null,
        {
        [...]
    

    That has caused rate limiting to come into effect, and now the calls are just hanging waiting to retry.

    reply: 'HTTP/1.1 429 Too Many Requests\r\n'
    retry-after: 42708
    

    Hopefully waiting a while for the wait limiting to be removed, and working out where the looping is, will fix the issue.

    It may also be an issue in Spotipy, if you try to query a playlist that is now no longer available, but for which you still know the ID, such as your Daylist, or if current_user_playlists is doing that. Querying those playlists now gives a 404.

    Try turning on urllib3 logging and see if you are also being rate-limited: Log all requests from the python-requests module