[GH-ISSUE #861] Unable to catch Spotify Exception using spotipy.SpotifyException #531

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

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

Describe the bug
I am unable to catch the exception thrown by Spotify using spotipy's SpotifyException objection or with generic error handling.

Your code

songURIList = []
for idx,_ in tqdm(dfBillboards[5660:5670].iterrows()):
    artist = dfBillboards['Artist'][idx]
    track = dfBillboards['Song'][idx]
    year = dfBillboards['Year'][idx]

    try:
        searchResults = sp.search(q=f"{artist}, {track}, {year}",type='track')
        if len(searchResults['tracks']['items'])>0:
            songURI = searchResults['tracks']['items'][0]['uri']
        else:
            songURI = 'Unavailable'
    except spotipy.SpotifyException:
        songURI = 'Unavailable'
    songURIList.append(songURI)

Expected behavior
I would normally expect the error to be caught and excepted. But that doesn't seem to be the case and I am unable to catch it with any method.

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 26, 2022). Original GitHub issue: https://github.com/spotipy-dev/spotipy/issues/861 **Describe the bug** I am unable to catch the exception thrown by Spotify using spotipy's SpotifyException objection or with generic error handling. **Your code** songURIList = [] for idx,_ in tqdm(dfBillboards[5660:5670].iterrows()): artist = dfBillboards['Artist'][idx] track = dfBillboards['Song'][idx] year = dfBillboards['Year'][idx] try: searchResults = sp.search(q=f"{artist}, {track}, {year}",type='track') if len(searchResults['tracks']['items'])>0: songURI = searchResults['tracks']['items'][0]['uri'] else: songURI = 'Unavailable' except spotipy.SpotifyException: songURI = 'Unavailable' songURIList.append(songURI) **Expected behavior** I would normally expect the error to be caught and excepted. But that doesn't seem to be the case and I am unable to catch it with any method. **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

@alexklann commented on GitHub (Aug 20, 2023):

So what was the error? Because I am running into the same issue...

<!-- gh-comment-id:1685423492 --> @alexklann commented on GitHub (Aug 20, 2023): So what was the error? Because I am running into the same issue...
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#531
No description provided.