spotipy: Spotipy doesnt doesnt respond but no error
Hello,
I have been using spotipy for the last year and never ran into any problems.
Today, I realized that something is not working anymore and looked into it.
I can initializing the sp.Spotify instance as usual without any problems, but if I then call a function (for example spotify.me() or spotify.devices(), it simply hangs and doesnt return anything.
This is the code I used for the last months:
with open("CONFIG.json", "r") as f:
config = json.load(f)
client_id = config["client_id"]
client_secret = config["client_secret"]
device_name = config["device_name"]
redirect_uri = config["redirect_uri"]
username = config["username"]
scope = config["scope"]
# authenticate account
auth_manager = SpotifyOAuth(
client_id=client_id,
client_secret=client_secret,
redirect_uri=redirect_uri,
scope=scope,
username=username
)
spotify = sp.Spotify(auth_manager=auth_manager)
I checked my Spotify dashboard, and noticed, that noticed that the number of daily requests dropped to zero just when December started:

Do you have any idea what might cause the issue? I already tried to regenerate a new client secret, but it didnt work.
I am using the version 2.21.0 on a raspberry pi (Raspbian version 10 [Buster])
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 31 (10 by maintainers)
I found the cause of the lack of response, and this is mentioned in https://github.com/urllib3/urllib3/issues/2911. In module urllib3/connectionpool.py, line #943 is code
This is honoring the Retry-After that Spotify’s API is sending back. And if you’re like me, who somehow got a long retry time (mine is currently 20k+ seconds), it is going to hang.
A potential fix is simply doing the following…
…so Spotify doesn’t try the retry. But if you do this, it just raises an Exception and doesn’t report back what the Retry-After value was. This is where the improvement can be made, and perhaps build Spotipy’s own retry feature.
Fair enough.
As we are talking about an undocumented “feature”, I don’t it can be resolved by the library, but reading this thread (and other similar threads about blocking code and long 429 retry times) there have been various answers and suggestions that completely miss the point of the error.
That’s why I commented, to highlight that the “Too Many Requests” error is exactly what it says, and not a rate-limit issue (in the usual sense).
Hopefully that will mean that people who search for “429” or “Too Many Requests” will understand that this isn’t an issue with Spotipy and that there isn’t much you can do to avoid the error other than limit the number of queries you make each day. The limit for album_tracks seems to be around 2300 per day (I’ve got 2300-2450 each day over the last couple of weeks). There may be limits for other endpoints, but I haven’t hit them. Reset for me always appears to be 20:00 UTC, give or take an hour.
I’ll leave it to you to decide whether this needs to be documented or an comment in Issues is sufficient.
Hi! I had a similar issue. I found that once a request gets denied, with each additional call you make following this, the wait time grows exponentially. Since I had a lot of calls to make (I’m doing a dataset augmentation task), I added an error catch for time out that looks like this:
Normally, it makes me wait like 8 hours and then I can come back.
Also, a few tips I have for making it less likely to time out:
Not sure whether you setting allows for these changes, but in the case that it does - hope it helps 😃
I’ve started working on a draft which would print a warning: #1134. Also another PR for adding a section to the FAQ (I can’t add it directly): #1133.
I probably could have done it in one PR, but too late for that now.
Thank you for that. I’ve tried to highlight this in the FAQ too.
I’ve done the sp.album_tracks query so that there is a second between each query, I’ve also done it so there is a minute between queries. Neither got a 429 rate limit until they had done 2000+ album queries, at which point both got 60k+ second waits.
Telling me that I’m wrong, and then adding “maybe it’s just the fact that you’re using a different endpoint” seems unproductive.
@spotifyr1 Hey, regarding this question “So when I use if int(e.headers[‘retry-after’]) > 60 to exit the loop, it doesn’t work because there is no ‘retry-after’ key in the headers. Do you know why that could happen? I’m printing out the values returned by the exception, and they all look fine except the header which is empty {}”, I don’t think spotipy has this returned. This is one of the reasons why I didn’t use spotipy client as the api, I directly called the REST API with the requests module, hence you don’t see me importing spotipy and just the requests module. With the requests module, you should be able to catch the retry-after value.