pythonspotipy

Spotipy library cannot access episodes using show_episodes function


I am using the spotipy published library to connect to Spotify API.

In order to get some data about podcast episodes.

When I access the function sp.search i get back a dictionary with all the data I need, but when I enter the show id or uri to get the episodes (sp.show_episodes()) it sends back the following message:

spotipy.exceptions.SpotifyException: http status: 404, code:-1 - https://api.spotify.com/v1/shows/2snXKBKP3rXeb9x6XquWmW/episodes/?limit=1&offset=0:

non existing id, reason: None

Here is the code:

results = sp.search(q='Israel category:Business', type='show', market=market, limit=50)


df = pd.DataFrame.from_dict(results)

# Filter podcasts by market and genre
business_podcasts = []
for item in results['shows']['items']:
    if 'IL' in item['available_markets']:
        business_podcasts.append(item)

# Extract relevant information from the filtered podcasts
podcasts = []


for podcast in business_podcasts:
    podcast_data = {
        'name': podcast['name'],
        'id': podcast['id'],
        'episode_count': podcast['total_episodes'],
        'uri': podcast['uri']

    }
    podcasts.append(podcast_data)

# Get episode duration for each podcast
for podcast in podcasts:


    episodes = sp.show_episodes(podcast['uri'], limit = 1)
    if episodes['items']:
        episode_duration = episodes['items'][0]['duration_ms']
        # Convert duration from milliseconds to seconds
        podcast['episode_duration'] = episode_duration / 1000
    else:
        podcast['episode_duration'] = None

Thank you very much!

Elad

I have checked several id's which are active and working, I also tried instead of sending the ID, to send the URI or href of the podcast, I expected to get a dictionary with the episoded of each show per id.

I got this message back - **# spotipy.exceptions.SpotifyException: http status: 404, code:-1 - https://api.spotify.com/v1/shows/2snXKBKP3rXeb9x6XquWmW/episodes/?limit=1&offset=0:

non existing id, reason: None**


Solution

  • You should add the market at: episodes = sp.show_episodes(podcast['uri'], limit = 1, market = market), because:

    Only episodes available in the given market will be returned. If user-based authorization is in use, the user’s country takes precedence. If neither market nor user country are provided, the content is considered unavailable for the client.