[GH-ISSUE #1164] Spotipy does not create .cache file after cloning #686

Closed
opened 2026-02-28 00:00:51 +03:00 by kerem · 4 comments
Owner

Originally created by @ethannwong on GitHub (Nov 2, 2024).
Original GitHub issue: https://github.com/spotipy-dev/spotipy/issues/1164

Describe the bug
I wrote a script to print a list of liked songs on Spotify which works on my old windows 10 laptop. I pushed the code to my repository and it does not work after I clone it on my new windows 11 laptop. Everything is the same, including the client id and secret. Running this code on my windows 11 laptop opens the authorization/permissions page on Spotify and if I click agree, it refreshes and does nothing if and if click one more time it shows a reload/buffer icon but doesn't do anything no matter how long I wait. My terminal seems to be waiting for something that doesn't come so I have to manually kill it because ctrl C doesn't work. I believe this is because there is no .cache file which I have on my old laptop but somehow isn't generated on my new one. Also when I run this code, my laptop opens the
Your code

import json
import requests
import spotipy
from spotipy.oauth2 import SpotifyOAuth
from googleapiclient.discovery import build
from google_auth_oauthlib.flow import InstalledAppFlow
from spotipy.oauth2 import SpotifyClientCredentials
import google.oauth2.credentials
import google_auth_oauthlib.flow
import argparse
import os
from googleapiclient.errors import HttpError

import os
from dotenv import load_dotenv

print("hi")

load_dotenv()

SPOTIFY_CLIENT_ID = os.getenv("SPOTIFY_CLIENT_ID")
SPOTIFY_CLIENT_SECRET = os.getenv("SPOTIFY_CLIENT_SECRET")



SPOTIFY_REDIRECT_URI = "http://localhost:3333/callback"
SPOTIFY_SCOPE = "user-library-read playlist-read-private"


sp = spotipy.Spotify(auth_manager=SpotifyOAuth(SPOTIFY_CLIENT_ID, SPOTIFY_CLIENT_SECRET, SPOTIFY_REDIRECT_URI, ["user-library-read","user-library-read-private","playlist-read-private"]))

print("connecting to Spotify")

spotify_playlist=[]
length_of_playlist=(sp.current_user_saved_tracks()['total'])

def playlist_formatter(start=0,end=length_of_playlist):
    if (end%50)>0:
        remainder=True
    else:
        remainder=False
    playlist_end_index=end%50
    p_remainder=end//50
    print("start and end is :", start,end)
    print("remainder offset and remainder is", p_remainder*50, remainder)
    

    global_idx=0
    if start !=0:
        first_song=sp.current_user_saved_tracks(limit=1,offset=start-1, market="US")
        spotify_playlist.append([0,first_song['items'][0]['track']['artists'][0]['name'],first_song['items'][0]['track']['name']])
        global_idx+=1
        print(spotify_playlist)

    for i in range(start,end,50):
        results = sp.current_user_saved_tracks(limit=50,offset=i,market="US")
        
        for idx, item in enumerate(results['items']):
            track= item['track']
            
            spotify_playlist.append([global_idx,track['artists'][0]['name'], track['name']])
            global_idx+=1
            if global_idx==(end-start+1):
                break
        print("first iter length: ", len(spotify_playlist)+1 )
        print("index number: ", i)
    
    print("length of spotify_playlist is: " , len(spotify_playlist))
    print(spotify_playlist)
    return(spotify_playlist)

playlist_formatter(5,57) 

Expected behavior
On my old laptop it should return a list of songs in my liked playlist, but my terminal is left waiting for something
Output
The permissions/auth page
image
My terminal
image

Paste and format errors (with complete stacktrace) or logs. Make sure to remove sensitive information.

Environment:

  • OS: [Windows 10, 11]
  • Python version [3.13]
  • spotipy version [2.24]
  • your IDE (if using any) [VS Code]

Additional context
Add any other context about the problem here.

Originally created by @ethannwong on GitHub (Nov 2, 2024). Original GitHub issue: https://github.com/spotipy-dev/spotipy/issues/1164 **Describe the bug** I wrote a script to print a list of liked songs on Spotify which works on my old windows 10 laptop. I pushed the code to my repository and it does not work after I clone it on my new windows 11 laptop. Everything is the same, including the client id and secret. Running this code on my windows 11 laptop opens the authorization/permissions page on Spotify and if I click agree, it refreshes and does nothing if and if click one more time it shows a reload/buffer icon but doesn't do anything no matter how long I wait. My terminal seems to be waiting for something that doesn't come so I have to manually kill it because ctrl C doesn't work. I believe this is because there is no .cache file which I have on my old laptop but somehow isn't generated on my new one. Also when I run this code, my laptop opens the **Your code** ``` import json import requests import spotipy from spotipy.oauth2 import SpotifyOAuth from googleapiclient.discovery import build from google_auth_oauthlib.flow import InstalledAppFlow from spotipy.oauth2 import SpotifyClientCredentials import google.oauth2.credentials import google_auth_oauthlib.flow import argparse import os from googleapiclient.errors import HttpError import os from dotenv import load_dotenv print("hi") load_dotenv() SPOTIFY_CLIENT_ID = os.getenv("SPOTIFY_CLIENT_ID") SPOTIFY_CLIENT_SECRET = os.getenv("SPOTIFY_CLIENT_SECRET") SPOTIFY_REDIRECT_URI = "http://localhost:3333/callback" SPOTIFY_SCOPE = "user-library-read playlist-read-private" sp = spotipy.Spotify(auth_manager=SpotifyOAuth(SPOTIFY_CLIENT_ID, SPOTIFY_CLIENT_SECRET, SPOTIFY_REDIRECT_URI, ["user-library-read","user-library-read-private","playlist-read-private"])) print("connecting to Spotify") spotify_playlist=[] length_of_playlist=(sp.current_user_saved_tracks()['total']) def playlist_formatter(start=0,end=length_of_playlist): if (end%50)>0: remainder=True else: remainder=False playlist_end_index=end%50 p_remainder=end//50 print("start and end is :", start,end) print("remainder offset and remainder is", p_remainder*50, remainder) global_idx=0 if start !=0: first_song=sp.current_user_saved_tracks(limit=1,offset=start-1, market="US") spotify_playlist.append([0,first_song['items'][0]['track']['artists'][0]['name'],first_song['items'][0]['track']['name']]) global_idx+=1 print(spotify_playlist) for i in range(start,end,50): results = sp.current_user_saved_tracks(limit=50,offset=i,market="US") for idx, item in enumerate(results['items']): track= item['track'] spotify_playlist.append([global_idx,track['artists'][0]['name'], track['name']]) global_idx+=1 if global_idx==(end-start+1): break print("first iter length: ", len(spotify_playlist)+1 ) print("index number: ", i) print("length of spotify_playlist is: " , len(spotify_playlist)) print(spotify_playlist) return(spotify_playlist) playlist_formatter(5,57) ``` **Expected behavior** On my old laptop it should return a list of songs in my liked playlist, but my terminal is left waiting for something **Output** The permissions/auth page ![image](https://github.com/user-attachments/assets/7078ef25-fc5d-47ec-b14f-f6419d4e7cd1) My terminal ![image](https://github.com/user-attachments/assets/79ab217f-b9d3-40b0-a741-9e9a8ee958d4) Paste and format errors (with complete stacktrace) or logs. Make sure to remove sensitive information. **Environment:** - OS: [Windows 10, 11] - Python version [3.13] - spotipy version [2.24] - your IDE (if using any) [VS Code] **Additional context** Add any other context about the problem here.
kerem 2026-02-28 00:00:51 +03:00
  • closed this issue
  • added the
    bug
    label
Author
Owner

@ethannwong commented on GitHub (Nov 2, 2024):

stupid code
gif of it not working

<!-- gh-comment-id:2453067473 --> @ethannwong commented on GitHub (Nov 2, 2024): ![stupid code](https://github.com/user-attachments/assets/62705d52-f036-4ecf-b209-f0a592b073e4) gif of it not working
Author
Owner

@dieser-niko commented on GitHub (Nov 2, 2024):

My guess is that the temporary web server is not available. As a workaround, I'd recommend setting open_browser=False like this:

SpotifyOAuth(open_browser=False, SPOTIFY_CLIENT_ID, ...)

This will prevent the http server from starting, but it's a bit more work.

As for the non-working server, I can't really pinpoint the problem. It could be an updated requirement for one of your other packages, or just another application on your system.
Can you make sure that the authentication flow works in a virtual environment with just spotipy installed?

<!-- gh-comment-id:2453123077 --> @dieser-niko commented on GitHub (Nov 2, 2024): My guess is that the temporary web server is not available. As a workaround, I'd recommend setting `open_browser=False` like this: ```python SpotifyOAuth(open_browser=False, SPOTIFY_CLIENT_ID, ...) ``` This will prevent the http server from starting, but it's a bit more work. As for the non-working server, I can't really pinpoint the problem. It could be an updated requirement for one of your other packages, or just another application on your system. Can you make sure that the authentication flow works in a virtual environment with just spotipy installed?
Author
Owner

@ethannwong commented on GitHub (Nov 2, 2024):

I think I removed my email I was using as one of the test users for some reason. I added it back and everything works now! Thank you so much!

<!-- gh-comment-id:2453164980 --> @ethannwong commented on GitHub (Nov 2, 2024): I think I removed my email I was using as one of the test users for some reason. I added it back and everything works now! Thank you so much!
Author
Owner

@dieser-niko commented on GitHub (Nov 3, 2024):

Thanks for the reply, I actually didn't know about this behaviour.

<!-- gh-comment-id:2453245650 --> @dieser-niko commented on GitHub (Nov 3, 2024): Thanks for the reply, I actually didn't know about this behaviour.
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#686
No description provided.