[GH-ISSUE #860] Search function doesn't result in the same result every time #529

Closed
opened 2026-02-27 23:23:10 +03:00 by kerem · 4 comments
Owner

Originally created by @chaitanya-gvs on GitHub (Sep 24, 2022).
Original GitHub issue: https://github.com/spotipy-dev/spotipy/issues/860

Describe the bug
The search function for tracks sometimes results in an empty array even though the songs are available on Spotify.

Your code
image

songURIList = [] # List to store the URIs
for idx,_ in tqdm(dfBillbaords[0:10].iterrows()):

    artist = dfBillbaords['Artist'][idx]
    track = dfBillbaords['Song'][idx]
    year = dfBillbaords['Year'][idx]

    searchResults = sp.search(q=f"artist: {artist} track: {track} year: {year}",type='track')

    if len(searchResults['tracks']['items'])>0:
        songURI = searchResults['tracks']['items'][0]['uri']   #Getting the URI of the first track in search result
    else:
        songURI = 'Unavailable'   #Assigning URI as 'Unavailable' 
    songURIList.append(songURI)
    time.sleep(5)

Expected behavior
The search result should be the same every time.
However the search result changes every time I run. It is not reproducible.

Output
Case 1:
image
Case 2:
image

Notice the difference in outputs between the two cases above,
The output is quite erratic and changing with every re-run.
The search function is failing to fetch the songs even if they're available.

Environment:

  • OS: Windows 11
  • Python version: 3.8.8
  • spotipy version: 2.2
  • IDE : Jupyter Notebook IDE
Originally created by @chaitanya-gvs on GitHub (Sep 24, 2022). Original GitHub issue: https://github.com/spotipy-dev/spotipy/issues/860 **Describe the bug** The search function for tracks sometimes results in an empty array even though the songs are available on Spotify. **Your code** ![image](https://user-images.githubusercontent.com/51097058/192117809-440953db-920d-4766-a1b7-450770a7dd8e.png) songURIList = [] # List to store the URIs for idx,_ in tqdm(dfBillbaords[0:10].iterrows()): artist = dfBillbaords['Artist'][idx] track = dfBillbaords['Song'][idx] year = dfBillbaords['Year'][idx] searchResults = sp.search(q=f"artist: {artist} track: {track} year: {year}",type='track') if len(searchResults['tracks']['items'])>0: songURI = searchResults['tracks']['items'][0]['uri'] #Getting the URI of the first track in search result else: songURI = 'Unavailable' #Assigning URI as 'Unavailable' songURIList.append(songURI) time.sleep(5) **Expected behavior** The search result should be the same every time. However the search result changes every time I run. It is not reproducible. **Output** Case 1: ![image](https://user-images.githubusercontent.com/51097058/192118199-e3272428-0c2c-40ab-ae35-a7b35a38523b.png) Case 2: ![image](https://user-images.githubusercontent.com/51097058/192118215-336c22e7-abe5-4908-99a6-152b10b93de4.png) Notice the difference in outputs between the two cases above, The output is quite erratic and changing with every re-run. The search function is failing to fetch the songs even if they're available. **Environment:** - OS: Windows 11 - Python version: 3.8.8 - spotipy version: 2.2 - IDE : Jupyter Notebook IDE
kerem 2026-02-27 23:23:10 +03:00
  • closed this issue
  • added the
    bug
    label
Author
Owner

@dpnem commented on GitHub (Sep 25, 2022):

I believe this is an Spotify API issue with the single quotes (') in the track names. If you remove the single quote from the track titles, you should be good.

Here's a quick search I did on "search track with single quote"

<!-- gh-comment-id:1257240607 --> @dpnem commented on GitHub (Sep 25, 2022): I believe this is an Spotify API issue with the single quotes (') in the track names. If you remove the single quote from the track titles, you should be good. Here's a quick search I did on "[search track with single quote](https://community.spotify.com/t5/forums/searchpage/tab/message?advanced=false&allow_punctuation=false&filter=location&location=forum-board:Spotify_Developer&q=search%20track%20with%20single%20quote)"
Author
Owner

@chaitanya-gvs commented on GitHub (Sep 26, 2022):

I don't think that's the case.
I have searched for tracks without single quotes in their names as well. And it still repeats.

<!-- gh-comment-id:1258121076 --> @chaitanya-gvs commented on GitHub (Sep 26, 2022): I don't think that's the case. I have searched for tracks without single quotes in their names as well. And it still repeats.
Author
Owner

@stephanebruckert commented on GitHub (Oct 29, 2022):

@Chaitanya98 your example does not really show that spotipy or the Spotify API is the issue.

Perhaps, your initial dataframe isn't the same or isn't ordered the same way every time?

I don't want to know what tqdm() is doing, but your example could be simplified to do the exact same query every time.

<!-- gh-comment-id:1295827220 --> @stephanebruckert commented on GitHub (Oct 29, 2022): @Chaitanya98 your example does not really show that spotipy or the Spotify API is the issue. Perhaps, your initial dataframe isn't the same or isn't ordered the same way every time? I don't want to know what `tqdm()` is doing, but your example could be simplified to do the exact same query every time.
Author
Owner

@stephanebruckert commented on GitHub (May 19, 2025):

Closing as we don't have a complete minimal example to investigate this

<!-- gh-comment-id:2892001148 --> @stephanebruckert commented on GitHub (May 19, 2025): Closing as we don't have a complete minimal example to investigate this
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#529
No description provided.