Announcements

Help Wizard

Step 1

NEXT STEP

Missing Retry_After header in 429 Response

Missing Retry_After header in 429 Response

Receiving the 429 error when making requests to the artist endpoint, the 'Retry-After' header is there, but this is not the case with the audio-features or audio-analysis endpoints. Here is my code:


def get_audio_analysis(track_id):
    try:
        url = 'https://api.spotify.com/v1/audio-analysis/'
        headers = get_auth_header(token_info['access_token'])
        query = track_id
        query_url = url + query
        response = requests.get(query_url, headers=headers)
        response.raise_for_status()
        audio_analysis = response.json()
        return audio_analysis

    except requests.exceptions.HTTPError as http_error:
        response = http_error.response
        retry_after = int(response.headers.get('Retry-After', 3600)
        # time.sleep(retry_after)

        # return get_audio_analysis(track_id)
        return response

 

inspecting the response with .headers returns:

{'content-type': 'application/json; charset=utf-8',
'cache-control': 'private, max-age=0',
'access-control-allow-origin': '*',
'access-control-allow-headers': 'Accept, App-Platform, Authorization, Content-Type, Origin, Retry-After, Spotify-App-Version, X-Cloud-Trace-Context, client-token, content-access-token',
'access-control-allow-methods': 'GET, POST, OPTIONS, PUT, DELETE, PATCH',
'access-control-allow-credentials': 'true',
'access-control-max-age': '604800',
'content-encoding': 'gzip',
'strict-transport-security': 'max-age=31536000',
'x-content-type-options': 'nosniff',
'date': 'Mon, 09 Oct 2023 07:21:39 GMT',
'server': 'envoy',
'Via': 'HTTP/2 edgeproxy, 1.1 google',
'Alt-Svc': 'h3=":443"; ma=2592000,h3-29=":443"; ma=2592000',
'Transfer-Encoding': 'chunked'}

As you can see, 'Retry-After' is present in the 'access-control-allow-headers' header, but not as a header itself.

 

Is it simply the case that not all endpoints include a 'Retry-After' header in the 429 response, or am I doing something wrong here? Any advice or answer would be appreciated.

Reply
1 Reply

Same issue here with the audio_analysis:

curl --request GET --url https://api.spotify.com/v1/audio-features/?ids=0aNMC2GQdN1ezXT3wK7WjB --header 'Authorization: Bearer my-token-here' -i

HTTP/2 429
content-type: application/json; charset=utf-8
cache-control: private, max-age=0
access-control-allow-origin: *
access-control-allow-headers: Accept, App-Platform, Authorization, Content-Type, Origin, Retry-After, Spotify-App-Version, X-Cloud-Trace-Context, client-token, content-access-token
access-control-allow-methods: GET, POST, OPTIONS, PUT, DELETE, PATCH
access-control-allow-credentials: true
access-control-max-age: 604800
content-length: 40
strict-transport-security: max-age=31536000
x-content-type-options: nosniff
vary: Accept-Encoding
date: Sun, 12 May 2024 16:41:37 GMT
server: envoy
via: HTTP/2 edgeproxy, 1.1 google
alt-svc: h3=":443"; ma=2592000,h3-29=":443"; ma=2592000

{
  "error" : {
    "status" : 429
  }

Suggested posts

Let's introduce ourselves!

Hey there you,   Yeah, you! 😁   Welcome - we're glad you joined the Spotify Community!   While you here, let's have a fun game and get…

ModeratorStaff / Moderator/ 4 years ago  in Social & Random