[GH-ISSUE #908] Possible bug, sp.next() freezes async bot. #546

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

Originally created by @BEMZ01 on GitHub (Nov 30, 2022).
Original GitHub issue: https://github.com/spotipy-dev/spotipy/issues/908

Hi there,

This segment of code has been giving me a headache for the last couple of days, whenever I call sp.next() my script freezes up as if it enters an infinate loop.

    class Music():
        async def play():
            ...
            try:
                playlist = sp.playlist(query, fields='tracks,name,id')
                with open('spotify.json', 'w') as f:
                    json.dump(playlist, f)
            # If the playlist is private, we can't access it.
            except spotipy.exceptions.SpotifyException:
                await message.delete()
                await ctx.respond("This playlist is private or doesn't exist.", delete_after=10, ephemeral=True)
                return
            # place all track names into a list
            tracks = []
            total_length = playlist['tracks']['total']
            play_name = playlist['name']
            # add track name and author to tracks
            for i, item in enumerate(playlist['tracks']['items']):
                tracks.append(f"{item['track']['name']} {item['track']['artists'][0]['name']}")
            while playlist['tracks']['next']:
                print("Tracks: ", len(tracks))
                playlist = sp.next(playlist['tracks'])
                with open('playlist_items.json', 'w') as f:
                    json.dump(playlist, f)
                print("Total length: ", total_length)
                for item in playlist['items']:
                    print("Appending: ", item['track']['name'])
                    track = item['track']
                    tracks.append(f"{track['name']} {track['artists'][0]['name']}")
                print("Tracks: ", len(tracks))
                
                ...

Not too sure if it's me overlooking something or a genuine bug, as the terminal isnt spitting any errors. I've looked through pottential issues

Originally created by @BEMZ01 on GitHub (Nov 30, 2022). Original GitHub issue: https://github.com/spotipy-dev/spotipy/issues/908 Hi there, This segment of code has been giving me a headache for the last couple of days, whenever I call sp.next() my script freezes up as if it enters an infinate loop. ``` class Music(): async def play(): ... try: playlist = sp.playlist(query, fields='tracks,name,id') with open('spotify.json', 'w') as f: json.dump(playlist, f) # If the playlist is private, we can't access it. except spotipy.exceptions.SpotifyException: await message.delete() await ctx.respond("This playlist is private or doesn't exist.", delete_after=10, ephemeral=True) return # place all track names into a list tracks = [] total_length = playlist['tracks']['total'] play_name = playlist['name'] # add track name and author to tracks for i, item in enumerate(playlist['tracks']['items']): tracks.append(f"{item['track']['name']} {item['track']['artists'][0]['name']}") while playlist['tracks']['next']: print("Tracks: ", len(tracks)) playlist = sp.next(playlist['tracks']) with open('playlist_items.json', 'w') as f: json.dump(playlist, f) print("Total length: ", total_length) for item in playlist['items']: print("Appending: ", item['track']['name']) track = item['track'] tracks.append(f"{track['name']} {track['artists'][0]['name']}") print("Tracks: ", len(tracks)) ... ``` Not too sure if it's me overlooking something or a genuine bug, as the terminal isnt spitting any errors. I've looked through pottential issues
kerem 2026-02-27 23:23:15 +03:00
  • closed this issue
  • added the
    question
    label
Author
Owner

@dieser-niko commented on GitHub (May 23, 2024):

Does it suddenly freeze or right at the beginning? I suspect you might have hit a request limit. urllib is then trying to wait until the rate limit is gone. However, this can take hours for some particular reason.

If you want to get an error instead, then you could do something like this:

sp = spotipy.Spotify(
    retries=0,
    ...
)
<!-- gh-comment-id:2126593227 --> @dieser-niko commented on GitHub (May 23, 2024): Does it suddenly freeze or right at the beginning? I suspect you might have hit a request limit. urllib is then trying to wait until the rate limit is gone. However, this can take hours for some particular reason. If you want to get an error instead, then you could do something like this: ```python sp = spotipy.Spotify( retries=0, ... ) ```
Author
Owner

@dieser-niko commented on GitHub (Jan 3, 2025):

Hi @BEMZ01, just a quick heads up, we have released a new version (2.25.0) that prints a warning when a limit is reached. I'm not sure if you're using retries=0, but if not, this change will warn you when you reach a limit.

Also I'm going to close this issue as there's no activity.

<!-- gh-comment-id:2569219972 --> @dieser-niko commented on GitHub (Jan 3, 2025): Hi @BEMZ01, just a quick heads up, we have released a new version (2.25.0) that prints a warning when a limit is reached. I'm not sure if you're using `retries=0`, but if not, this change will warn you when you reach a limit. Also I'm going to close this issue as there's no activity.
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#546
No description provided.