-
Notifications
You must be signed in to change notification settings - Fork 962
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
Hanging track search #937
Comments
I'm not sure why you have
because spotipy is supposed to refresh the token automatically without it. It would be good to have a complete code that we could run to show the problem. Even if's doing a loop over the same track and it takes 30 minutes. Any chance you can provide that? |
Yes, of course! I was trying to give you a simple MVP. But if you'd like my full code, here it is. Given a csv with spotify uris I load the albums and artists associated with them and then also scrape info about those albums/artists. In
in
And finally in launch.py:
|
Thanks! Would you have a sample csv too please? |
Yes! It can be downloaded from this link. Select the option The loop itself runs for about 30 minutes and then cuts out. As evidenced by the output here:
The code doesn't exit, just stays hanging. Thank you for your help! |
@Rsalganik1123 sorry this is a bit complex to run. There is no main function. Please can you provide a minimal reproducible example? For example something that would be as simple as this and would reproduce the issue for you:
Btw I have been running this ^ for 1.5 hours and it's still running well. Anything that would change on your side? Also, your code contains |
Hello, using the MVE that you suggested, I will place the code below, I am able to reproduce the error.
the output is:
And now it's hanging. Could it be because I'm running the code from a distributed server? Thank you! |
Interesting! What do you mean exactly by distributed server? |
I'm running on an academic server which uses a SLURM scheduler to dispatch jobs to various compute nodes. To be honest, I'm not super familiar with the appropriate terminology to describe the architecture. |
Really not sure, it still should be one job running on one node with internet access. Perhaps there are some firewalls on the way or the requests are blocked. It would be great if you could try your code outside this server (for example locally) and/or with another internet connection. It's really strange that it stops after 2 requests only? Did you say the same was not happening with We can try to show debug logs, just add this to the top of the file:
It should show something like the following (just make sure to remove your access token after
Also, when you cancel it with |
I can try it locally and report back later today.
And then it remains hanging.
|
Ha! It sounds like this is related #892 Seeing it stopped at I'll have a better look to try and confirm this. |
Interesting! But then why would that differ from sp.audio_features? |
Actually that was a false lead. It's hanging while trying to retry which is unrelated to the token expiry time. This discussion is quite interesting #766. It mentions the possibility that the Spotify API can request to retry in 3600 seconds. I'm not sure why it would be so high, maybe a bug on their side. In the meantime you could try to use this answer #766 (comment) to force a failure, but still wait 1 sec before trying again. import requests
import urllib3
import spotipy
from spotipy.oauth2 import SpotifyClientCredentials
from spotipy.exceptions import SpotifyException
import time
session = requests.Session()
retry = urllib3.Retry(
respect_retry_after_header=False
)
adapter = requests.adapters.HTTPAdapter(max_retries=retry)
sp = spotipy.Spotify(auth_manager=SpotifyClientCredentials(),
requests_session=session)
i = 0
while True:
try:
res = sp.track('spotify:track:3HPHPoXFupNZXfnFXmiJI5')
except SpotifyException as e:
if e.http_status == 429:
print("'retry-after' value:", e.headers['retry-after'])
time.sleep(1)
else:
break
print(res['uri'], str(i))
i += 1 Notice it prints the "retry-after" value given by the API. What value do you get?
Perhaps for |
Yes! Thank you, I will try it later today and report back. |
This works.
Trying the same thing by replacing |
Also, running with my local machine doesn't have any issues with latency or hanging. So I'm not sure why but it's something about running on the nodes that's causing problems. Could it be because I have an allocation of 2 cpus and there is some sort of multi-threading happening that causes the time out? |
No I don't think anything that elaborate is happening. Your
Make sense! |
I see. So for now the only solution is to: A. clear the cache before scraping, B. manually set the retry-after to 1 second ? Is that correct? |
Unfortunately, the error is back. Despite cleaning my cache I am getting a 429 error and a 'retry-after' value: 63397 |
At this point it's not really a spotipy error/bug anymore as you are just being rate-limited by Spotify. Why such a high retry-after value I am not sure but it could be related to the node. Here are other ideas you could experiment with:
Let us know what your findings are or if you have any other questions, but for now I think it's fair to close this as there is not much we can do inside spotipy. |
I have a function that retrieves me all songs from a playlist and it does it succesfully when called. But when try to use other function that includes sp.album() or sp.album_tracks() the program gets stuck whenever executing album() or album_tracks(). It cant be due to rate-limit cause everything works when not using album() or album_tracks() nor with token/keys. |
Let's continue this discussion in #913 |
Describe the bug
Sometimes, the
sp.track()
just hangs without an error and without a return but at the same time,sp.audio_features()
works properly.Your code
And when I call
sp.audio_features(uri)
it responds immediately but when I callsp.track(uri)
it can hang up to more than 3 minutes before I ctrl+C out of the code even though I set a timeout value.After reading a few GitHub issues (see #913 , #862, #844, etc) it seems that there may be an issue with the spotify token going stale but I am not sure how to fix this since I am following the methodology of the README for initializing my credentials. I know that the URI is valid because it was working for about 30 minutes and then it stopped. Since I doing an augmentation for a large dataset, I need to be able to refresh my token.
Expected behavior
Throwing either an error or returning the search query.
Output
None and I'm not sure how to debug for one.
Environment:
Additional context
Add any other context about the problem here.
The text was updated successfully, but these errors were encountered: