Spotipy API Returns cache error

Does anyone know what causes this error? It looks like it’s related to the cache directory, I’m not sure if it’s how Replit handles things or if there is an error with my code, but any help is appreciated.

Error:
Couldn’t read cache at: .cache
Couldn’t write token to cache at: .cache

Code:

import spotipy
from spotipy.oauth2 import SpotifyClientCredentials

# Add Spotify Credentials
spotify_id = "" # (removed for privacy)
spotify_secret = "" # (removed for privacy)

sp = spotipy.Spotify(auth_manager=SpotifyClientCredentials(
  client_id=spotify_id, client_secret=spotify_secret))

results = sp.search(q='weezer', limit=20)
for idx, track in enumerate(results['tracks']['items']):
  print(idx, track['name'])

My project isn’t published just yet, so I created a screenshot and pasted the code here.

Hey @joshrodg, welcome to the community!

Though this won’t fix your problem, use secrets to hide your Spotify credentials:

import os
import spotipy
from spotipy.oauth2 import SpotifyClientCredentials

# Add Spotify Credentials
spotify_id = os.environ["spotify_id"]
spotify_secret = os.environn["spotify_secret"]

sp = spotipy.Spotify(auth_manager=SpotifyClientCredentials(
  client_id=spotify_id, client_secret=spotify_secret))

results = sp.search(q='weezer', limit=20)
for idx, track in enumerate(results['tracks']['items']):
  print(idx, track['name'])

Then go to Tools → Secrets and add in your id and secret as secrets.

Anyone can view your Repl even if it isn’t published. I can simply go to https://replit.com/@joshrodg/Spotify-Playlist-Checker?v=1#main.py.

3 Likes

@QwertyQwerty88 is there a way to edit my post? I can’t find a link anywhere

1 Like

There should be a pencil icon next to the heart button.

@QwertyQwerty88 i don’t see one, but I’m on mobile…I’ll check when I get home :slight_smile: thanks!!

If I write a print statement on my offset, that seems to be the culprit for my issue because it seems to be occurring after every offset. Does anyone see a problem with the offset that’s in the code?

Thanks,
Josh

1 Like