[GH-ISSUE #209] Issue adding to Playlist #163

Closed
opened 2026-02-27 22:08:23 +03:00 by kerem · 5 comments
Owner

Originally created by @KaneSama2k3 on GitHub (Jul 1, 2021).
Original GitHub issue: https://github.com/sigma67/ytmusicapi/issues/209

I'm trying to create a series of playlists from my complete library and I'm getting the following error when trying to upload to a playlist

  File "\lib\site-packages\ytmusicapi\mixins\playlists.py", line 273, in add_playlist_items
    response = self._send_request(endpoint, body)
  File "\lib\site-packages\ytmusicapi\ytmusic.py", line 133, in _send_request
    raise Exception(message + error)
Exception: Server returned HTTP 400: Bad Request.
Precondition check failed.

The fetch requests work fine

Originally created by @KaneSama2k3 on GitHub (Jul 1, 2021). Original GitHub issue: https://github.com/sigma67/ytmusicapi/issues/209 I'm trying to create a series of playlists from my complete library and I'm getting the following error when trying to upload to a playlist ``` File "\lib\site-packages\ytmusicapi\mixins\playlists.py", line 273, in add_playlist_items response = self._send_request(endpoint, body) File "\lib\site-packages\ytmusicapi\ytmusic.py", line 133, in _send_request raise Exception(message + error) Exception: Server returned HTTP 400: Bad Request. Precondition check failed. ``` The fetch requests work fine
kerem closed this issue 2026-02-27 22:08:23 +03:00
Author
Owner

@sigma67 commented on GitHub (Jul 1, 2021):

Difficult to say what's going on here without function parameters. I assume there is something wrong with the playlistId or videoIds you used.

<!-- gh-comment-id:872376612 --> @sigma67 commented on GitHub (Jul 1, 2021): Difficult to say what's going on here without function parameters. I assume there is something wrong with the playlistId or videoIds you used.
Author
Owner

@KaneSama2k3 commented on GitHub (Jul 1, 2021):

Ah; understood.
I have a program that fetches all the videoIds in my account, saves them to a file (because I was trying to deal with crashes and didn't want to keep fetching every time there was a minor error) and then runs the output file against this:

def upload_list(playlist_prefix: str, my_list: List[str], chunk_size: int):
    yt_music = YTMusic('header_auth.json')
    res = []
    [res.append(x) for x in my_list if x not in res]
    counter = 0
    for record in chunked(res, chunk_size):
        counter += 1
        converted_list = []
        new_playlist = yt_music.create_playlist(playlist_prefix + ' ' + str(counter), 'Music from API')
        converted_list = []
        for element in record:
            converted_list.append(element.strip())
        test = yt_music.add_playlist_items(new_playlist, converted_list)
        print(test)
        time.sleep(60)
        while test != 'STATUS_SUCCEEDED':
            time.sleep(60)
            if test.get('actions') and test.get('actions')[0].get('addToToastAction').get('item').get(
                    'notificationActionRenderer').get('responseText').get('runs') and \
                    test.get('actions')[0].get('addToToastAction').get('item').get('notificationActionRenderer').get(
                        'responseText').get('runs')[0].get('text') == 'This song is already in the playlist':
                test = 'STATUS_SUCCEEDED'
            else:
                yt_music = YTMusic('header_auth.json')
                test = yt_music.add_playlist_items(new_playlist, record)
                print(test)

So the playlist Id is fetched from the creation and the videoIds are fetched from my library
The crash occurs on the add_playlist_items step. I usually use 500 as the chunk size for my lists, but I tried 1 and it still crashes straight away

<!-- gh-comment-id:872472277 --> @KaneSama2k3 commented on GitHub (Jul 1, 2021): Ah; understood. I have a program that fetches all the videoIds in my account, saves them to a file (because I was trying to deal with crashes and didn't want to keep fetching every time there was a minor error) and then runs the output file against this: ``` def upload_list(playlist_prefix: str, my_list: List[str], chunk_size: int): yt_music = YTMusic('header_auth.json') res = [] [res.append(x) for x in my_list if x not in res] counter = 0 for record in chunked(res, chunk_size): counter += 1 converted_list = [] new_playlist = yt_music.create_playlist(playlist_prefix + ' ' + str(counter), 'Music from API') converted_list = [] for element in record: converted_list.append(element.strip()) test = yt_music.add_playlist_items(new_playlist, converted_list) print(test) time.sleep(60) while test != 'STATUS_SUCCEEDED': time.sleep(60) if test.get('actions') and test.get('actions')[0].get('addToToastAction').get('item').get( 'notificationActionRenderer').get('responseText').get('runs') and \ test.get('actions')[0].get('addToToastAction').get('item').get('notificationActionRenderer').get( 'responseText').get('runs')[0].get('text') == 'This song is already in the playlist': test = 'STATUS_SUCCEEDED' else: yt_music = YTMusic('header_auth.json') test = yt_music.add_playlist_items(new_playlist, record) print(test) ``` So the playlist Id is fetched from the creation and the videoIds are fetched from my library The crash occurs on the add_playlist_items step. I usually use 500 as the chunk size for my lists, but I tried 1 and it still crashes straight away
Author
Owner

@sigma67 commented on GitHub (Jul 1, 2021):

Did you try printing the playlistId, opening the playlist in a browser, and adding videos manually?

<!-- gh-comment-id:872478751 --> @sigma67 commented on GitHub (Jul 1, 2021): Did you try printing the playlistId, opening the playlist in a browser, and adding videos manually?
Author
Owner

@KaneSama2k3 commented on GitHub (Jul 1, 2021):

OK; so I'm officially really p***ed at myself. It is indeed a Video Id that no longer exists. My fetch routine gets all the songs in my playlists, library and uploaded, dedupes them and saves. I had turned off the the playlist fetch, but not the import so it was looking at old data.
I only realised this by stepping through the ids one at a time rather than batching them.
Sorry for wasting your time, and thanks for the incredibly useful tool to make YouTube music usable

<!-- gh-comment-id:872589734 --> @KaneSama2k3 commented on GitHub (Jul 1, 2021): OK; so I'm officially really p***ed at myself. It is indeed a Video Id that no longer exists. My fetch routine gets all the songs in my playlists, library and uploaded, dedupes them and saves. I had turned off the the playlist fetch, but not the import so it was looking at old data. I only realised this by stepping through the ids one at a time rather than batching them. Sorry for wasting your time, and thanks for the incredibly useful tool to make YouTube music usable
Author
Owner

@sigma67 commented on GitHub (Jul 2, 2021):

No worries! Always double check your data :)

<!-- gh-comment-id:872775036 --> @sigma67 commented on GitHub (Jul 2, 2021): No worries! Always double check your data :)
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/ytmusicapi#163
No description provided.