[GH-ISSUE #1064] user_playlist_create won't create playlist despite the correct parameters being passed through #625

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

Originally created by @JoshPauls94 on GitHub (Dec 21, 2023).
Original GitHub issue: https://github.com/spotipy-dev/spotipy/issues/1064

This code was working fine all day for me, then I went for lunch and came back to create a new playlist and now it wont work.
Please help

It keeps running this line of code for half an hour, by which point I interrupt the process
playlist = sp.user_playlist_create(USERNAME, playlist_name, public=False, description=playlist_description)

Entire code is below

import spotipy
from spotipy.oauth2 import SpotifyOAuth
import pandas as pd

df_sorted_2 = pd.read_csv('/Documents/coding_projects/partoo/new_radio_round_up.csv')

# Spotify API credentials
CLIENT_ID = client_id
CLIENT_SECRET = client_secret
REDIRECT_URI = 'http://localhost:3000'
USERNAME = username

# Set up Spotify authentication
sp = spotipy.Spotify(auth_manager=SpotifyOAuth(client_id=CLIENT_ID,
                                               client_secret=CLIENT_SECRET,
                                               redirect_uri=REDIRECT_URI,
                                               scope='playlist-modify-private'))

# Create a new playlist
playlist_name = '4th Do You!! Roundup 2023'
playlist_description = 'Charlie Bones web scrape'
print("Creating playlist.....")
playlist = sp.user_playlist_create(USERNAME, playlist_name, public=False, description=playlist_description)
print("Playlist has been created")

# Search for each song in the CSV and add it to the playlist
for index, row in df_sorted_2.iterrows():
    track_name = row['Track Title']
    artist_name = row['Artist']
    # Use the Spotify API to search for the track
    try:    
        # Refine the search query by including the artist name
        search_query = f'{track_name} artist:{artist_name}'
        
        # Use the Spotify API to search for the track
        results = sp.search(q=search_query, type='track', limit=1)
        if results['tracks']['items']:
            track_uri = results['tracks']['items'][0]['uri']
            # Add the track to the playlist
            sp.playlist_add_items(playlist['id'], [track_uri])
        else:
            print(f"Track not found: {track_name} by {artist_name}")
    except spotipy.SpotifyException as e:
        print(f"Error searching for {track_name} by {artist_name}: {e}")
        # Continue to the next iteration of the loop if there's an error
        continue

print(f"Playlist '{playlist_name}' created successfully.")
Originally created by @JoshPauls94 on GitHub (Dec 21, 2023). Original GitHub issue: https://github.com/spotipy-dev/spotipy/issues/1064 This code was working fine all day for me, then I went for lunch and came back to create a new playlist and now it wont work. Please help It keeps running this line of code for half an hour, by which point I interrupt the process playlist = sp.user_playlist_create(USERNAME, playlist_name, public=False, description=playlist_description) Entire code is below ```python import spotipy from spotipy.oauth2 import SpotifyOAuth import pandas as pd df_sorted_2 = pd.read_csv('/Documents/coding_projects/partoo/new_radio_round_up.csv') # Spotify API credentials CLIENT_ID = client_id CLIENT_SECRET = client_secret REDIRECT_URI = 'http://localhost:3000' USERNAME = username # Set up Spotify authentication sp = spotipy.Spotify(auth_manager=SpotifyOAuth(client_id=CLIENT_ID, client_secret=CLIENT_SECRET, redirect_uri=REDIRECT_URI, scope='playlist-modify-private')) # Create a new playlist playlist_name = '4th Do You!! Roundup 2023' playlist_description = 'Charlie Bones web scrape' print("Creating playlist.....") playlist = sp.user_playlist_create(USERNAME, playlist_name, public=False, description=playlist_description) print("Playlist has been created") # Search for each song in the CSV and add it to the playlist for index, row in df_sorted_2.iterrows(): track_name = row['Track Title'] artist_name = row['Artist'] # Use the Spotify API to search for the track try: # Refine the search query by including the artist name search_query = f'{track_name} artist:{artist_name}' # Use the Spotify API to search for the track results = sp.search(q=search_query, type='track', limit=1) if results['tracks']['items']: track_uri = results['tracks']['items'][0]['uri'] # Add the track to the playlist sp.playlist_add_items(playlist['id'], [track_uri]) else: print(f"Track not found: {track_name} by {artist_name}") except spotipy.SpotifyException as e: print(f"Error searching for {track_name} by {artist_name}: {e}") # Continue to the next iteration of the loop if there's an error continue print(f"Playlist '{playlist_name}' created successfully.") ```
kerem 2026-02-28 00:00:22 +03:00
  • closed this issue
  • added the
    question
    label
Author
Owner

@Kudzmat commented on GitHub (Jan 19, 2024):

Are you getting error messages?

<!-- gh-comment-id:1900584279 --> @Kudzmat commented on GitHub (Jan 19, 2024): Are you getting error messages?
Author
Owner

@dieser-niko commented on GitHub (Jul 31, 2024):

Closing as there is no activity or reply from the author.

<!-- gh-comment-id:2260223760 --> @dieser-niko commented on GitHub (Jul 31, 2024): Closing as there is no activity or reply from the author.
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#625
No description provided.