[GH-ISSUE #805] 500 error code in sp.audio_features() reported as 429 #501

Open
opened 2026-02-27 23:22:58 +03:00 by kerem · 8 comments
Owner

Originally created by @jkulak on GitHub (May 5, 2022).
Original GitHub issue: https://github.com/spotipy-dev/spotipy/issues/805

Describe the bug
500 error code in sp.audio_features() reported as 429

Your code
For this particular ID, https://developer.spotify.com/console/get-audio-features-several-tracks/ returns 500.

audio_features = sp.audio_features(tracks=["1tkkrLY3upIwNfLs4ei8Bh"])

Spotipy returns:

 "exception": "SpotifyException(429, -1, '/v1/audio-features/?ids=1tkkrLY3upIwNfLs4ei8Bh:\\n Max Retries')"

Expected behavior
I would expect Spotipy to show me that it is a 500 error code. So I could debug and verify which ID is causing the issue on Spotify's side. When I am getting 429 I am assuming it is a limit error.

Environment:

  • OS: Mac, Docker
  • Python version 3.10.2
  • spotipy version spotipy = "==2.19.0"
  • VS Code

Additional context
The request exception is caught here: github.com/plamere/spotipy@9a627e88f4/spotipy/client.py (L274)

And then it is raising 429 here: github.com/plamere/spotipy@9a627e88f4/spotipy/client.py (L281)

Originally created by @jkulak on GitHub (May 5, 2022). Original GitHub issue: https://github.com/spotipy-dev/spotipy/issues/805 **Describe the bug** `500` error code in `sp.audio_features()` reported as `429` **Your code** For this particular ID, https://developer.spotify.com/console/get-audio-features-several-tracks/ returns 500. ``` audio_features = sp.audio_features(tracks=["1tkkrLY3upIwNfLs4ei8Bh"]) ``` Spotipy returns: ``` "exception": "SpotifyException(429, -1, '/v1/audio-features/?ids=1tkkrLY3upIwNfLs4ei8Bh:\\n Max Retries')" ``` **Expected behavior** I would expect Spotipy to show me that it is a `500` error code. So I could debug and verify which ID is causing the issue on Spotify's side. When I am getting `429` I am assuming it is a limit error. **Environment:** - OS: Mac, Docker - Python version 3.10.2 - spotipy version spotipy = "==2.19.0" - VS Code **Additional context** The request exception is caught here: https://github.com/plamere/spotipy/blob/9a627e88f422927822ce39ae9919cc7ab9813dde/spotipy/client.py#L274 And then it is raising `429` here: https://github.com/plamere/spotipy/blob/9a627e88f422927822ce39ae9919cc7ab9813dde/spotipy/client.py#L281
Author
Owner

@jkulak commented on GitHub (May 5, 2022):

Btw. those ids also return 500 from Spotify's API for audio_features.

  • 2QIWo90LTeI3MXDCzgwXMb
  • 3Db20yiHMSUFP60rqFMny5
  • 11mVBkAjzJy70VamIgsEOL

(It is an ASMR album with ultrasonic sounds)

<!-- gh-comment-id:1118867337 --> @jkulak commented on GitHub (May 5, 2022): Btw. those ids also return `500` from Spotify's API for audio_features. * `2QIWo90LTeI3MXDCzgwXMb` * `3Db20yiHMSUFP60rqFMny5` * `11mVBkAjzJy70VamIgsEOL` (It is an ASMR album with ultrasonic sounds)
Author
Owner

@Peter-Schorn commented on GitHub (May 6, 2022):

What makes you so sure that 429 is the wrong error? How do you know that your requests aren't getting rate-limited by Spotify?

Have you used the debugger to determine that spotipy returns a rate-limited error even when the raw network response from the requests module contains a 500 status code?

<!-- gh-comment-id:1119323146 --> @Peter-Schorn commented on GitHub (May 6, 2022): What makes you so sure that `429` is the wrong error? How do you know that your requests aren't getting rate-limited by Spotify? Have you used the debugger to determine that spotipy returns a rate-limited error even when the raw network response from the requests module contains a `500` status code?
Author
Owner

@jkulak commented on GitHub (May 6, 2022):

Hey. I checked what error code is returned when requesting same url using same token using Spotify’s console and then also using Postman. It returns 500 in both cases.

Spotipy returns 429 (same token, same url, before and after I tested in console).

It’s super easy to check using code samples and IDs I provided.

<!-- gh-comment-id:1119328513 --> @jkulak commented on GitHub (May 6, 2022): Hey. I checked what error code is returned when requesting same url using same token using Spotify’s console and then also using Postman. It returns 500 in both cases. Spotipy returns 429 (same token, same url, before and after I tested in console). It’s super easy to check using code samples and IDs I provided.
Author
Owner

@dasbts commented on GitHub (May 6, 2022):

I got the same issue and error (max retries) when feeding a list of songs, and when searching for it (by link in browser and the URI ofc.) it said it was unavailable, however it was not a local song and I got the song info for it when requesting a playlist of songs. My thought is it might just not be available in your market.

My solution after trying multiple fixes is to just if you want to also fetch other songs, do a try except, and just ignore the one that doesn't work.

It's not rate limiting, at least not in my case, because all songs except some few ones don't work, and the try except allows me to fetch multiple other songs and just skip these that are retrying.

<!-- gh-comment-id:1119401457 --> @dasbts commented on GitHub (May 6, 2022): I got the same issue and error (max retries) when feeding a list of songs, and when searching for it (by link in browser and the URI ofc.) it said it was unavailable, however it was not a local song and I got the song info for it when requesting a playlist of songs. My thought is it might just not be available in your market. My solution after trying multiple fixes is to just if you want to also fetch other songs, do a try except, and just ignore the one that doesn't work. It's not rate limiting, at least not in my case, because all songs except some few ones don't work, and the try except allows me to fetch multiple other songs and just skip these that are retrying.
Author
Owner

@Peter-Schorn commented on GitHub (May 6, 2022):

I was unable to reproduce the rate-limited error with any of the ids although I did get a 500 error with all of these ids. I don't know why this error is returned for certain tracks, but it's clear that this is not due to an issue on spotipy's end because I get the same error when I make the request in Postman. You'll have to ask about this on the Spotify Developer Forums.

Spotipy returns 429 (same token, same url, before and after I tested in console).

Rate limiting is applied on a per-developer application basis, not a per-access token basis, so try creating a new developer application (which means you'll get a new client id and client secret) and then use this application with spotipy only for a single request. Can you still reproduce the rate-limited error?

<!-- gh-comment-id:1119648335 --> @Peter-Schorn commented on GitHub (May 6, 2022): I was unable to reproduce the rate-limited error with any of the ids although I did get a 500 error with all of these ids. I don't know why this error is returned for certain tracks, but it's clear that this is not due to an issue on spotipy's end because I get the same error when I make the request in Postman. You'll have to ask about this on the [Spotify Developer Forums](https://community.spotify.com/t5/Spotify-for-Developers/bd-p/Spotify_Developer). > Spotipy returns 429 (same token, same url, before and after I tested in console). Rate limiting is applied on a per-developer application basis, not a per-access token basis, so try creating a new developer application (which means you'll get a new client id and client secret) and then use this application with spotipy only for a single request. Can you still reproduce the rate-limited error?
Author
Owner

@jkulak commented on GitHub (May 6, 2022):

Thank you for your answers, I appreciate your time.

You'll have to ask about this on the Spotify Developer Forums.

Yes. But I don't mind 500s from Spotify for some IDs - it happens, it is ok. But I would like Spotipy to show me it was a 500 on Spotify's end and not 429.

This code (assuming you have your env SPOTIPY_CLIENT_ID and SPOTIPY_CLIENT_SECRET)

import spotipy
from spotipy.oauth2 import SpotifyClientCredentials

sp = spotipy.Spotify(auth_manager=SpotifyClientCredentials())
result = sp.audio_features(tracks=["1tkkrLY3upIwNfLs4ei8Bh"])

Results in urllib3 exception, caught and passed byrequests exception and then caught by Spotipy and then reported as spotipy.exceptions.SpotifyException: http status: 429. Which (in my opinion) is not correct, becase my rate limits are OK, and Spotify returns 500 for this particular request (albo same market etc.). Full Traceback (Pastebin for convenience, line 42, https://pastebin.com/1SHAQJbH):

(app) /app # python 500_test.py
Max Retries reached
Traceback (most recent call last):
  File "/root/.local/share/virtualenvs/app-4PlAip0Q/lib/python3.10/site-packages/requests/adapters.py", line 440, in send
    resp = conn.urlopen(
  File "/root/.local/share/virtualenvs/app-4PlAip0Q/lib/python3.10/site-packages/urllib3/connectionpool.py", line 876, in urlopen
    return self.urlopen(
  File "/root/.local/share/virtualenvs/app-4PlAip0Q/lib/python3.10/site-packages/urllib3/connectionpool.py", line 876, in urlopen
    return self.urlopen(
  File "/root/.local/share/virtualenvs/app-4PlAip0Q/lib/python3.10/site-packages/urllib3/connectionpool.py", line 876, in urlopen
    return self.urlopen(
  File "/root/.local/share/virtualenvs/app-4PlAip0Q/lib/python3.10/site-packages/urllib3/connectionpool.py", line 866, in urlopen
    retries = retries.increment(method, url, response=response, _pool=self)
  File "/root/.local/share/virtualenvs/app-4PlAip0Q/lib/python3.10/site-packages/urllib3/util/retry.py", line 592, in increment
    raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='api.spotify.com', port=443): Max retries exceeded with url: /v1/audio-features/?ids=1tkkrLY3upIwNfLs4ei8Bh (Caused by ResponseError('too many 500 error responses'))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/root/.local/share/virtualenvs/app-4PlAip0Q/lib/python3.10/site-packages/spotipy/client.py", line 240, in _internal_call
    response = self._session.request(
  File "/root/.local/share/virtualenvs/app-4PlAip0Q/lib/python3.10/site-packages/requests/sessions.py", line 529, in request
    resp = self.send(prep, **send_kwargs)
  File "/root/.local/share/virtualenvs/app-4PlAip0Q/lib/python3.10/site-packages/requests/sessions.py", line 645, in send
    r = adapter.send(request, **kwargs)
  File "/root/.local/share/virtualenvs/app-4PlAip0Q/lib/python3.10/site-packages/requests/adapters.py", line 510, in send
    raise RetryError(e, request=request)
requests.exceptions.RetryError: HTTPSConnectionPool(host='api.spotify.com', port=443): Max retries exceeded with url: /v1/audio-features/?ids=1tkkrLY3upIwNfLs4ei8Bh (Caused by ResponseError('too many 500 error responses'))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/app/500_test.py", line 5, in <module>
    result = sp.audio_features(tracks=["1tkkrLY3upIwNfLs4ei8Bh"])
  File "/root/.local/share/virtualenvs/app-4PlAip0Q/lib/python3.10/site-packages/spotipy/client.py", line 1683, in audio_features
    results = self._get("audio-features/?ids=" + ",".join(tlist))
  File "/root/.local/share/virtualenvs/app-4PlAip0Q/lib/python3.10/site-packages/spotipy/client.py", line 297, in _get
    return self._internal_call("GET", url, payload, kwargs)
  File "/root/.local/share/virtualenvs/app-4PlAip0Q/lib/python3.10/site-packages/spotipy/client.py", line 281, in _internal_call
    raise SpotifyException(
spotipy.exceptions.SpotifyException: http status: 429, code:-1 - /v1/audio-features/?ids=1tkkrLY3upIwNfLs4ei8Bh:
 Max Retries, reason: too many 500 error responses
(app) /app #

Btw. I am working with several applications and CLIENT_IDs, I am sure I am not hitting rate limits (triple checked).

<!-- gh-comment-id:1119779084 --> @jkulak commented on GitHub (May 6, 2022): Thank you for your answers, I appreciate your time. > You'll have to ask about this on the [Spotify Developer Forums](https://community.spotify.com/t5/Spotify-for-Developers/bd-p/Spotify_Developer). Yes. But I don't mind 500s from Spotify for some IDs - it happens, it is ok. **But I would like Spotipy to show me it was a 500 on Spotify's end and not 429**. This code (assuming you have your env `SPOTIPY_CLIENT_ID` and `SPOTIPY_CLIENT_SECRET`) ``` import spotipy from spotipy.oauth2 import SpotifyClientCredentials sp = spotipy.Spotify(auth_manager=SpotifyClientCredentials()) result = sp.audio_features(tracks=["1tkkrLY3upIwNfLs4ei8Bh"]) ``` Results in `urllib3` exception, caught and passed by`requests` exception and then caught by Spotipy and then reported as `spotipy.exceptions.SpotifyException: http status: 429`. Which (in my opinion) is not correct, becase my rate limits are OK, and Spotify returns `500` for this particular request (albo same market etc.). Full Traceback (Pastebin for convenience, line 42, https://pastebin.com/1SHAQJbH): ``` (app) /app # python 500_test.py Max Retries reached Traceback (most recent call last): File "/root/.local/share/virtualenvs/app-4PlAip0Q/lib/python3.10/site-packages/requests/adapters.py", line 440, in send resp = conn.urlopen( File "/root/.local/share/virtualenvs/app-4PlAip0Q/lib/python3.10/site-packages/urllib3/connectionpool.py", line 876, in urlopen return self.urlopen( File "/root/.local/share/virtualenvs/app-4PlAip0Q/lib/python3.10/site-packages/urllib3/connectionpool.py", line 876, in urlopen return self.urlopen( File "/root/.local/share/virtualenvs/app-4PlAip0Q/lib/python3.10/site-packages/urllib3/connectionpool.py", line 876, in urlopen return self.urlopen( File "/root/.local/share/virtualenvs/app-4PlAip0Q/lib/python3.10/site-packages/urllib3/connectionpool.py", line 866, in urlopen retries = retries.increment(method, url, response=response, _pool=self) File "/root/.local/share/virtualenvs/app-4PlAip0Q/lib/python3.10/site-packages/urllib3/util/retry.py", line 592, in increment raise MaxRetryError(_pool, url, error or ResponseError(cause)) urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='api.spotify.com', port=443): Max retries exceeded with url: /v1/audio-features/?ids=1tkkrLY3upIwNfLs4ei8Bh (Caused by ResponseError('too many 500 error responses')) During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/root/.local/share/virtualenvs/app-4PlAip0Q/lib/python3.10/site-packages/spotipy/client.py", line 240, in _internal_call response = self._session.request( File "/root/.local/share/virtualenvs/app-4PlAip0Q/lib/python3.10/site-packages/requests/sessions.py", line 529, in request resp = self.send(prep, **send_kwargs) File "/root/.local/share/virtualenvs/app-4PlAip0Q/lib/python3.10/site-packages/requests/sessions.py", line 645, in send r = adapter.send(request, **kwargs) File "/root/.local/share/virtualenvs/app-4PlAip0Q/lib/python3.10/site-packages/requests/adapters.py", line 510, in send raise RetryError(e, request=request) requests.exceptions.RetryError: HTTPSConnectionPool(host='api.spotify.com', port=443): Max retries exceeded with url: /v1/audio-features/?ids=1tkkrLY3upIwNfLs4ei8Bh (Caused by ResponseError('too many 500 error responses')) During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/app/500_test.py", line 5, in <module> result = sp.audio_features(tracks=["1tkkrLY3upIwNfLs4ei8Bh"]) File "/root/.local/share/virtualenvs/app-4PlAip0Q/lib/python3.10/site-packages/spotipy/client.py", line 1683, in audio_features results = self._get("audio-features/?ids=" + ",".join(tlist)) File "/root/.local/share/virtualenvs/app-4PlAip0Q/lib/python3.10/site-packages/spotipy/client.py", line 297, in _get return self._internal_call("GET", url, payload, kwargs) File "/root/.local/share/virtualenvs/app-4PlAip0Q/lib/python3.10/site-packages/spotipy/client.py", line 281, in _internal_call raise SpotifyException( spotipy.exceptions.SpotifyException: http status: 429, code:-1 - /v1/audio-features/?ids=1tkkrLY3upIwNfLs4ei8Bh: Max Retries, reason: too many 500 error responses (app) /app # ``` Btw. I am working with several applications and CLIENT_IDs, I am sure I am not hitting rate limits (triple checked).
Author
Owner

@jkulak commented on GitHub (Aug 4, 2022):

@Peter-Schorn where you able to reproduce it? I am willing to help.

<!-- gh-comment-id:1205847522 --> @jkulak commented on GitHub (Aug 4, 2022): @Peter-Schorn where you able to reproduce it? I am willing to help.
Author
Owner

@neilmenon commented on GitHub (Sep 15, 2023):

Hello @Peter-Schorn,

I've just had the same thing happen to me and see it reported here as well: https://github.com/home-assistant/core/issues/88547

spotify.playlist_upload_cover_image(created_playlist_id, base64_image)

gives

Exception: http status: 429, code:-1 - /v1/playlists/{id}/images: Max Retries, reason: too many 500 error responses

This was definitely not a rate-limit because it was the first call in several hours. Any ideas why it's being reported as 429?

Thanks!

<!-- gh-comment-id:1721350624 --> @neilmenon commented on GitHub (Sep 15, 2023): Hello @Peter-Schorn, I've just had the same thing happen to me and see it reported here as well: https://github.com/home-assistant/core/issues/88547 ```python spotify.playlist_upload_cover_image(created_playlist_id, base64_image) ``` gives ``` Exception: http status: 429, code:-1 - /v1/playlists/{id}/images: Max Retries, reason: too many 500 error responses ``` This was definitely not a rate-limit because it was the first call in several hours. Any ideas why it's being reported as 429? 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#501
No description provided.