Spotipy: Getting error 'Couldn't read cache at: .cache' with example code

Created on 30 Sep 2020  Â·  3Comments  Â·  Source: plamere/spotipy

Describe the bug
Using the example auth code I get the error 'Couldn't read cache at: .cache' I've tried looking around but can't find a reference to this specific error anywhere. I'm using the Online IDE repl.it but it seems users have used it with no trouble before looking at other projects

Your code
import spotipy
from spotipy.oauth2 import SpotifyOAuth

scope = "user-library-read"

sp = spotipy.Spotify(auth_manager=SpotifyOAuth(scope=scope))

results = sp.current_user_saved_tracks()
for idx, item in enumerate(results['items']):
track = item['track']
print(idx, track['artists'][0]['name'], " – ", track['name'])

Environment:

  • OS: [Linux Container (I believe)]
  • Python version [e.g. 3.8.2]
  • spotipy version [e.g. 2.16.0]
  • your IDE (if using any) [Repl.it]

*

bug

Most helpful comment

(note: I am a newbie to open-source contributing, feedback on my correctness would be appreciated)

This is expected behaviour for (initial) runs of Spotipy as far the current version allows. Line 310 of spotipy/oauth2.py illustrates that Spotipy throws this warning if a cache file for tokens has not yet been instantiated. This is a relatively new feature (see #567) to allow explicit specification of cache files to be optional, hence probably why you can't find other documentation.

This shouldn't prevent your code from working. On repeat executions, the error goes away regardless (unless you keep changing the working directory...!); otherwise, I guess if you instantiate the file .cache in the working directory prior to using SpotifyOAuth() you can avoid the warning, but this feels impractical. Hope that helps!

All 3 comments

(note: I am a newbie to open-source contributing, feedback on my correctness would be appreciated)

This is expected behaviour for (initial) runs of Spotipy as far the current version allows. Line 310 of spotipy/oauth2.py illustrates that Spotipy throws this warning if a cache file for tokens has not yet been instantiated. This is a relatively new feature (see #567) to allow explicit specification of cache files to be optional, hence probably why you can't find other documentation.

This shouldn't prevent your code from working. On repeat executions, the error goes away regardless (unless you keep changing the working directory...!); otherwise, I guess if you instantiate the file .cache in the working directory prior to using SpotifyOAuth() you can avoid the warning, but this feels impractical. Hope that helps!

This is true @Quizz1Cal, it is just a warning so don't worry about it. Probably that your current environment (repl.it) doesn't allow storing new files. Can you open an issue on their side to ask if this is expected?

In the meantime, let us know if this issue prevents you from using any other features

That may be it, I ended up manually doing the oauth which took a bit more time but ended up working, thanks. It did continue on every run though so I was unable to use this library. Thanks for making it though if it worked in my enviroment it definitely would have been a great help but not the fault of you then but on their end.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

AnySomebody1 picture AnySomebody1  Â·  3Comments

DylanMeeus picture DylanMeeus  Â·  4Comments

Kurchunk picture Kurchunk  Â·  3Comments

astralmedia picture astralmedia  Â·  4Comments

tatoosh picture tatoosh  Â·  5Comments