[GH-ISSUE #1224] spotipy not timing out when getting error 429 #713

Closed
opened 2026-02-28 00:01:06 +03:00 by kerem · 2 comments
Owner

Originally created by @mkatrhae on GitHub (Dec 23, 2025).
Original GitHub issue: https://github.com/spotipy-dev/spotipy/issues/1224

Spotipy hangs forever and never times out when an api quota limit has been reached (default timeout is 5s). Object is created like this:

cache_handler = spotipy.cache_handler.CacheFileHandler("./.spotify_cache")
    auth_manager = spotipy.oauth2.SpotifyOAuth(
        cache_handler = cache_handler,
        client_id = ...
        client_secret= ...
        redirect_uri="http://127.0.0.1:8888/authresult",
        scope=scope,
        requests_timeout=1,
    )
    sp = spotipy.Spotify(auth_manager = auth_manager)

   print(sp.me())  # <--- hangs

I even tried to inject an external retry mechanism

 session = requests.Session()

    retry = Retry(
        total=1,
        connect=1,
        read=1,
        backoff_factor=0.5,
        status_forcelist=[429, 500, 502, 503, 504],
        allowed_methods=["POST", "GET"],
    )

    adapter = HTTPAdapter(max_retries=retry)
    session.mount("https://", adapter)

Expected behavior
Being able to detect this scenario with something like
except SpotifyException as e:

Output

File /usr/lib/python3/dist-packages/urllib3/connectionpool.py:882, in HTTPConnectionPool.urlopen(self, method, url, body, headers, retries, redirect, assert_same_host, timeout, pool_timeout, release_conn, chunked, body_pos, **response_kw)
    879     return response
    881 response.drain_conn()
--> 882 retries.sleep(response)
    883 log.debug("Retry: %s", url)
    884 return self.urlopen(
    885     method,
    886     url,
   (...)
    897     **response_kw
    898 )

File /usr/lib/python3/dist-packages/urllib3/util/retry.py:430, in Retry.sleep(self, response)
    421 """Sleep between retry attempts.
    422 
    423 This method will respect a server's ``Retry-After`` response header
   (...)
    426 this method will return immediately.
    427 """
    429 if self.respect_retry_after_header and response:
--> 430     slept = self.sleep_for_retry(response)
    431     if slept:
    432         return

File /usr/lib/python3/dist-packages/urllib3/util/retry.py:409, in Retry.sleep_for_retry(self, response)
    407 retry_after = self.get_retry_after(response)
    408 if retry_after:
--> 409     time.sleep(retry_after)
    410     return True
    412 return False

Environment:

  • OS: Linux
  • Python version: 3.11.2
  • spotipy version: 2.24.0
  • your IDE: none
Originally created by @mkatrhae on GitHub (Dec 23, 2025). Original GitHub issue: https://github.com/spotipy-dev/spotipy/issues/1224 Spotipy hangs forever and never times out when an api quota limit has been reached (default timeout is 5s). Object is created like this: ```python cache_handler = spotipy.cache_handler.CacheFileHandler("./.spotify_cache") auth_manager = spotipy.oauth2.SpotifyOAuth( cache_handler = cache_handler, client_id = ... client_secret= ... redirect_uri="http://127.0.0.1:8888/authresult", scope=scope, requests_timeout=1, ) sp = spotipy.Spotify(auth_manager = auth_manager) print(sp.me()) # <--- hangs ``` I even tried to inject an external retry mechanism ```python session = requests.Session() retry = Retry( total=1, connect=1, read=1, backoff_factor=0.5, status_forcelist=[429, 500, 502, 503, 504], allowed_methods=["POST", "GET"], ) adapter = HTTPAdapter(max_retries=retry) session.mount("https://", adapter) ``` **Expected behavior** Being able to detect this scenario with something like `except SpotifyException as e: ` **Output** ```python File /usr/lib/python3/dist-packages/urllib3/connectionpool.py:882, in HTTPConnectionPool.urlopen(self, method, url, body, headers, retries, redirect, assert_same_host, timeout, pool_timeout, release_conn, chunked, body_pos, **response_kw) 879 return response 881 response.drain_conn() --> 882 retries.sleep(response) 883 log.debug("Retry: %s", url) 884 return self.urlopen( 885 method, 886 url, (...) 897 **response_kw 898 ) File /usr/lib/python3/dist-packages/urllib3/util/retry.py:430, in Retry.sleep(self, response) 421 """Sleep between retry attempts. 422 423 This method will respect a server's ``Retry-After`` response header (...) 426 this method will return immediately. 427 """ 429 if self.respect_retry_after_header and response: --> 430 slept = self.sleep_for_retry(response) 431 if slept: 432 return File /usr/lib/python3/dist-packages/urllib3/util/retry.py:409, in Retry.sleep_for_retry(self, response) 407 retry_after = self.get_retry_after(response) 408 if retry_after: --> 409 time.sleep(retry_after) 410 return True 412 return False ``` **Environment:** - OS: Linux - Python version: 3.11.2 - spotipy version: 2.24.0 - your IDE: none
kerem 2026-02-28 00:01:06 +03:00
  • closed this issue
  • added the
    bug
    label
Author
Owner

@dieser-niko commented on GitHub (Dec 23, 2025):

Please refer to our FAQ: https://github.com/spotipy-dev/spotipy/blob/master/FAQ.md#my-application-is-not-responding
Specifically the second part on how to turn it off.

<!-- gh-comment-id:3687416488 --> @dieser-niko commented on GitHub (Dec 23, 2025): Please refer to our FAQ: https://github.com/spotipy-dev/spotipy/blob/master/FAQ.md#my-application-is-not-responding Specifically the second part on how to turn it off.
Author
Owner

@mkatrhae commented on GitHub (Dec 24, 2025):

I'll check it, thank you!

<!-- gh-comment-id:3689924326 --> @mkatrhae commented on GitHub (Dec 24, 2025): I'll check it, thank you!
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#713
No description provided.