Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Spotipy's sleep_for_retry() function? #956

Closed
CalColistra opened this issue Mar 30, 2023 · 1 comment
Closed

Spotipy's sleep_for_retry() function? #956

CalColistra opened this issue Mar 30, 2023 · 1 comment
Labels

Comments

@CalColistra
Copy link

CalColistra commented Mar 30, 2023

I have been using spotify's spotipy (python) api and my program is getting stuck on a sleep_for_retry(). I can see the sequence of functions being called in my python notebook and it gets stuck at this:
artist() > _get() >_internal_call() > request() > send() > send() > urlopen() > sleep() > sleep_for_retry()

Wondering how to avoid their sleep_for_retry() function? I am struggling to find any documentation regarding that function but i have seen some people suggesting this: time.sleep(<some amount of time here>) but I can't figure out how to get that working.

Does anyone have experience with this? I love the spotipy API and I would like to keep using it but I don't want to be making more requests than their server can handle.

the error looks like this:

--> 321         return self._internal_call("GET", url, payload, kwargs)
    322 
    323     def _post(self, url, args=None, payload=None, **kwargs):

/usr/local/lib/python3.9/dist-packages/spotipy/client.py in _internal_call(self, method, url, payload, params)
    262 
    263         try:
--> 264             response = self._session.request(
    265                 method, url, headers=headers, proxies=self.proxies,
    266                 timeout=self.requests_timeout, **args

/usr/local/lib/python3.9/dist-packages/requests/sessions.py in request(self, method, url, params, data, headers, cookies, files, auth, timeout, allow_redirects, proxies, hooks, stream, verify, cert, json)
    527         }
    528         send_kwargs.update(settings)
--> 529         resp = self.send(prep, **send_kwargs)
    530 
    531         return resp

/usr/local/lib/python3.9/dist-packages/requests/sessions.py in send(self, request, **kwargs)
    643 
    644         # Send the request
--> 645         r = adapter.send(request, **kwargs)
    646 
    647         # Total elapsed time of the request (approximately)

/usr/local/lib/python3.9/dist-packages/requests/adapters.py in send(self, request, stream, timeout, verify, cert, proxies)
    438         try:
    439             if not chunked:
--> 440                 resp = conn.urlopen(
    441                     method=request.method,
    442                     url=url,

/usr/local/lib/python3.9/dist-packages/urllib3/connectionpool.py in urlopen(self, method, url, body, headers, retries, redirect, assert_same_host, timeout, pool_timeout, release_conn, chunked, body_pos, **response_kw)
    874 
    875             response.drain_conn()
--> 876             retries.sleep(response)
    877             log.debug("Retry: %s", url)
    878             return self.urlopen(

/usr/local/lib/python3.9/dist-packages/urllib3/util/retry.py in sleep(self, response)
    426 
    427         if self.respect_retry_after_header and response:
--> 428             slept = self.sleep_for_retry(response)
    429             if slept:
    430                 return

/usr/local/lib/python3.9/dist-packages/urllib3/util/retry.py in sleep_for_retry(self, response)
    405         retry_after = self.get_retry_after(response)
    406         if retry_after:
--> 407             time.sleep(retry_after)
    408             return True
@stephanebruckert
Copy link
Member

stephanebruckert commented Mar 30, 2023

spotipy should already be waiting/sleeping when the Spotify API response requests to wait (retry-after value). Maybe there is a scenario where this does not apply.

Therefore I'm asking, would you have a Minimal reproducible example that would allow us to reproduce this rate limiting? This would need to work with a new Spotify app.

Feel free to include logs about the current retry-after value, maybe with inspiration from #913 (comment)?

I'm closing to close so we can all discuss in the same thread. Please post your response in #913

@CalColistra CalColistra changed the title How can you abide by Spotipy's sleep_for_retry() function? Spotipy's sleep_for_retry() function? May 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants