[GH-ISSUE #762] "time.sleep(retry_after)" and "Invalid client" Error #465

Closed
opened 2026-02-27 23:22:47 +03:00 by kerem · 2 comments
Owner

Originally created by @Naka7su on GitHub (Dec 24, 2021).
Original GitHub issue: https://github.com/spotipy-dev/spotipy/issues/762

Content

Nice to meet you.

"My user information(?)" suddenly doesn't work in "spotipy".
For example, nothing happens inputing user id in "sp.user_playlists()", and
"sp.user_playlist_add_tracks()" doesn't reference my "playlist_id".
So I run "control+c", and the program say "~... time.sleep(retry_after)".
This result is the same about any program.
So I tried re-creating the dashboard and re-authenticating again, but "Invalid client" occurred.
I don't know what to do.

The Code

(the following is first code) → "time.sleep(retry_after)" Error

import itertools
import spotipy
import spotipy.util as util
from datetime import date, timedelta
import time
import sys

username = ''
my_id ='' #client ID
my_secret = '' #client secret
redirect_uri = 'http://localhost:8888/callback/' 

scope = 'user-library-read playlist-read-private playlist-read-collaborative playlist-modify-public playlist-modify-private'

token = util.prompt_for_user_token(username, scope, my_id, my_secret, redirect_uri)
sp = spotipy.Spotify(auth = token)

#
yesterday_numeric = date.today() - timedelta(days=1)
yesterday_string = yesterday_numeric.strftime('%Y-%m-%d')
'''  '''
all_playlist_name = sp.user_playlists(username)
'''  '''
playlist_url_YN = []
for items_1 in all_playlist_name['items']:
    if yesterday_string == items_1['name']:
        playlist_url = items_1['external_urls']['spotify']
        playlist_url_YN.append('yes')
    else:
        pass   
if playlist_url_YN == []:
    sp.user_playlist_create(username,yesterday_string)
    '''  '''
    all_playlist_name_2 = sp.user_playlists(username)
    '''  '''
    for items_2 in all_playlist_name_2['items']:
        if yesterday_string == items_2['name']:
            playlist_url = items_2['external_urls']['spotify']
        else:
            pass
else:
    pass

start = time.perf_counter()

#
''''''
alphabet = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']
artist_urls = []
for i in range(3):
    if i == 0:
        pass
    else:
        for v in itertools.permutations(alphabet,i):
            def Search_Artist_Loop(a=0):
                '''  '''
                all_1 = sp.search(q=''.join(v),limit=1,offset=a,type='artist')
                '''  '''
                for items_3 in all_1['artists']['items']:
                    artist_urls.append(items_3['external_urls']['spotify'])
                if a == 950:
                    pass
                else:
                    Search_Artist_Loop(a=a+50)
            Search_Artist_Loop()
            print(len(artist_urls))
            artist_urls = list(set(artist_urls))
            print(len(artist_urls))
        print(str(len(artist_urls)) + ' artists...')

end = time.perf_counter()
print(end - start)


''''''
yesterday_release_musics = []
def Search_Artist_Album_Loop():
    for items_4 in artist_urls:
        def Search_Artist_Album_Loop_2(b=0):
            time.sleep(0.01)
            '''  '''
            all_2 = sp.artist_albums(items_4,limit=50,offset=b)
            '''  '''
            for items_5 in all_2['items']:
                url_1 = items_5['external_urls']['spotify']
                time.sleep(0.01)
                '''  '''
                release_date = sp.album(url_1)['release_date']
                '''  '''
                if yesterday_string == release_date:
                    '''  '''
                    for items_6 in sp.album(url_1)['tracks']['items']:
                        '''  '''
                        yesterday_release_musics.append(items_6['external_urls']['spotify'])
                else:
                    pass
            if all_2['total'] < b+50:
                pass
            else:
                Search_Artist_Album_Loop_2(b=b+50)
        Search_Artist_Album_Loop_2()      
Search_Artist_Album_Loop()
yesterday_release_musics = list(set(yesterday_release_musics))  
print('Finish Searching !!')

end = time.perf_counter()
print(end - start)

#
if yesterday_release_musics == []:
    pass
else:
    '''  '''
    sp.user_playlist_add_tracks(username,playlist_url,yesterday_release_musics)
    '''  '''
print('Finish All !!')

(the following is second code) → "Invalid client" Error

import spotipy
import spotipy.util as util

scope = 'user-library-read playlist-read-private playlist-read-collaborative playlist-modify-public playlist-modify-private'
token = util.prompt_for_user_token(
    'my_user_id',
    scope,
    client_id='my_new_client_id',
    client_secret='my_new_client_secret_id', redirect_uri='http://localhost:8888/callback') 

sp = spotipy.Spotify(auth=token)
print('ok')

Other

It happened while I was writing and running the program.
Maybe, I was stopped from using the program because of the large number of requests?
I’d like to ask you for your help on this problem please.

Environment

  • Spotify Plan
    Premium
  • Device
    Macbook Air (M1, 2020)
  • Operating System
    macOS Monterey 12.0.1

I'm a beginner in programming and I think they are poorly coded, and this is my first time using "Github".
So please forgive me for any unsightly parts.

Originally created by @Naka7su on GitHub (Dec 24, 2021). Original GitHub issue: https://github.com/spotipy-dev/spotipy/issues/762 ### Content Nice to meet you. "My user information(?)" suddenly doesn't work in "spotipy". For example, nothing happens inputing user id in "sp.user_playlists()", and "sp.user_playlist_add_tracks()" doesn't reference my "playlist_id". So I run "control+c", and the program say "~... time.sleep(retry_after)". This result is the same about any program. So I tried re-creating the dashboard and re-authenticating again, but "Invalid client" occurred. I don't know what to do. ### The Code (the following is first code) → "time.sleep(retry_after)" Error ``` python import itertools import spotipy import spotipy.util as util from datetime import date, timedelta import time import sys username = '' my_id ='' #client ID my_secret = '' #client secret redirect_uri = 'http://localhost:8888/callback/' scope = 'user-library-read playlist-read-private playlist-read-collaborative playlist-modify-public playlist-modify-private' token = util.prompt_for_user_token(username, scope, my_id, my_secret, redirect_uri) sp = spotipy.Spotify(auth = token) # yesterday_numeric = date.today() - timedelta(days=1) yesterday_string = yesterday_numeric.strftime('%Y-%m-%d') ''' ''' all_playlist_name = sp.user_playlists(username) ''' ''' playlist_url_YN = [] for items_1 in all_playlist_name['items']: if yesterday_string == items_1['name']: playlist_url = items_1['external_urls']['spotify'] playlist_url_YN.append('yes') else: pass if playlist_url_YN == []: sp.user_playlist_create(username,yesterday_string) ''' ''' all_playlist_name_2 = sp.user_playlists(username) ''' ''' for items_2 in all_playlist_name_2['items']: if yesterday_string == items_2['name']: playlist_url = items_2['external_urls']['spotify'] else: pass else: pass start = time.perf_counter() # '''''' alphabet = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'] artist_urls = [] for i in range(3): if i == 0: pass else: for v in itertools.permutations(alphabet,i): def Search_Artist_Loop(a=0): ''' ''' all_1 = sp.search(q=''.join(v),limit=1,offset=a,type='artist') ''' ''' for items_3 in all_1['artists']['items']: artist_urls.append(items_3['external_urls']['spotify']) if a == 950: pass else: Search_Artist_Loop(a=a+50) Search_Artist_Loop() print(len(artist_urls)) artist_urls = list(set(artist_urls)) print(len(artist_urls)) print(str(len(artist_urls)) + ' artists...') end = time.perf_counter() print(end - start) '''''' yesterday_release_musics = [] def Search_Artist_Album_Loop(): for items_4 in artist_urls: def Search_Artist_Album_Loop_2(b=0): time.sleep(0.01) ''' ''' all_2 = sp.artist_albums(items_4,limit=50,offset=b) ''' ''' for items_5 in all_2['items']: url_1 = items_5['external_urls']['spotify'] time.sleep(0.01) ''' ''' release_date = sp.album(url_1)['release_date'] ''' ''' if yesterday_string == release_date: ''' ''' for items_6 in sp.album(url_1)['tracks']['items']: ''' ''' yesterday_release_musics.append(items_6['external_urls']['spotify']) else: pass if all_2['total'] < b+50: pass else: Search_Artist_Album_Loop_2(b=b+50) Search_Artist_Album_Loop_2() Search_Artist_Album_Loop() yesterday_release_musics = list(set(yesterday_release_musics)) print('Finish Searching !!') end = time.perf_counter() print(end - start) # if yesterday_release_musics == []: pass else: ''' ''' sp.user_playlist_add_tracks(username,playlist_url,yesterday_release_musics) ''' ''' print('Finish All !!') ``` (the following is second code) → "Invalid client" Error ``` python import spotipy import spotipy.util as util scope = 'user-library-read playlist-read-private playlist-read-collaborative playlist-modify-public playlist-modify-private' token = util.prompt_for_user_token( 'my_user_id', scope, client_id='my_new_client_id', client_secret='my_new_client_secret_id', redirect_uri='http://localhost:8888/callback') sp = spotipy.Spotify(auth=token) print('ok') ``` ### Other It happened while I was writing and running the program. Maybe, I was stopped from using the program because of the large number of requests? I’d like to ask you for your help on this problem please. ### Environment - Spotify Plan Premium - Device Macbook Air (M1, 2020) - Operating System macOS Monterey 12.0.1 _I'm a beginner in programming and I think they are poorly coded, and this is my first time using "Github". So please forgive me for any unsightly parts._
kerem 2026-02-27 23:22:47 +03:00
  • closed this issue
  • added the
    question
    label
Author
Owner

@Naka7su commented on GitHub (Dec 29, 2021):

I was able to solve the problem on my own.
By clearing the cache file in my home directory, the error does not appear!!

<!-- gh-comment-id:1002763539 --> @Naka7su commented on GitHub (Dec 29, 2021): I was able to solve the problem on my own. By clearing the cache file in my home directory, the error does not appear!!
Author
Owner

@m-riley04 commented on GitHub (Nov 10, 2022):

Hey, I don't know if you're even still on Git but I'm having a similar issue where my program stalls/hangs whenever it tries to pull an image from a URL. I tried clearing my cache in the file directory, but is there another place I should clear it?

<!-- gh-comment-id:1310457362 --> @m-riley04 commented on GitHub (Nov 10, 2022): Hey, I don't know if you're even still on Git but I'm having a similar issue where my program stalls/hangs whenever it tries to pull an image from a URL. I tried clearing my cache in the file directory, but is there another place I should clear it?
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#465
No description provided.