So I'm iterating over a huge .csv file which each row contains a song name and an artist name. For each of these rows I have to write into another file the track id of this song.
I have been running the program but I get this error after an hour:
"The access token expired"
I been reading and it seems the token expires after an hour. Is there any way I can reload the token during my execution?
This is the function I wrote to get the song ID
def getSongId(artist, title, songMap):
index = artist + title
trackId = 'null'
try:
trackId = songMap[index]
print("HashMap used")
except KeyError:
try:
resultats = spotify.search(q='artist:' + artist + ' track:' + title, type='track')
trackId = resultats['tracks']['items'][0]['id']
songMap[index] = trackId
except IndexError:
trackId = 'null'
return trackId, songMap
This is the error I get:
spotipy.client.SpotifyException: http status: 401, code:-1 - https://api.spotify.com/v1/search?q=artist%3AZadye+Wolf+track%3AHustler&limit=10&offset=0&type=track: The access token expired
Thanks you very much