[GH-ISSUE #19] Hitting an API rate limit raises KeyError from create_playlist() #14

Closed
opened 2026-02-27 22:07:33 +03:00 by kerem · 6 comments
Owner

Originally created by @beville on GitHub (May 16, 2020).
Original GitHub issue: https://github.com/sigma67/ytmusicapi/issues/19

In my experimentation auto-generating playlists, I started getting a KeyError from create_playlist().

Traceback (most recent call last):
  File "./ytmusic.py", line 153, in <module>
    main()
  File "./ytmusic.py", line 148, in main
    replace_playlist(ytmusic, playlist_name, track_ids)
  File "./ytmusic.py", line 124, in replace_playlist
    id = ytmusic.create_playlist(title, desc)
  File "/usr/local/lib/python3.8/dist-packages/ytmusicapi/ytmusic.py", line 782, in create_playlist
    return response['playlistId']
KeyError: 'playlistId'

I stuck a debug in there, and saw this in the JSON response:

{'error': {'code': 429, 'message': 'You are creating too many playlists. Please wait a while before creating further playlists.', 'errors': [{'message': 'You are creating too many playlists. Please wait a while before creating further playlists.', 'domain': 'gdata.CoreErrorDomain', 'reason': 'RATE_LIMIT_EXCEEDED'}], 'status': 'RESOURCE_EXHAUSTED'}}

The python API should probably catch this and return an error code or throw a custom exception.

Originally created by @beville on GitHub (May 16, 2020). Original GitHub issue: https://github.com/sigma67/ytmusicapi/issues/19 In my experimentation auto-generating playlists, I started getting a KeyError from create_playlist(). ``` Traceback (most recent call last): File "./ytmusic.py", line 153, in <module> main() File "./ytmusic.py", line 148, in main replace_playlist(ytmusic, playlist_name, track_ids) File "./ytmusic.py", line 124, in replace_playlist id = ytmusic.create_playlist(title, desc) File "/usr/local/lib/python3.8/dist-packages/ytmusicapi/ytmusic.py", line 782, in create_playlist return response['playlistId'] KeyError: 'playlistId' ``` I stuck a debug in there, and saw this in the JSON response: > {'error': {'code': 429, 'message': 'You are creating too many playlists. Please wait a while before creating further playlists.', 'errors': [{'message': 'You are creating too many playlists. Please wait a while before creating further playlists.', 'domain': 'gdata.CoreErrorDomain', 'reason': 'RATE_LIMIT_EXCEEDED'}], 'status': 'RESOURCE_EXHAUSTED'}} The python API should probably catch this and return an error code or throw a custom exception.
kerem closed this issue 2026-02-27 22:07:34 +03:00
Author
Owner

@sigma67 commented on GitHub (May 17, 2020):

Interesting, this is the first time I've come across rate limits in their API. I agree that this should be caught with a custom exception.

Do you have an estimate on what the limit is? We might want to include that in the error message.

<!-- gh-comment-id:629784031 --> @sigma67 commented on GitHub (May 17, 2020): Interesting, this is the first time I've come across rate limits in their API. I agree that this should be caught with a custom exception. Do you have an estimate on what the limit is? We might want to include that in the error message.
Author
Owner

@beville commented on GitHub (May 17, 2020):

I don't have a solid idea of the limit.

I was testing a function that takes a playlist title, searches the results of get_library_playlists() for that then, and then creates the playlist it if title is missing. Even though the call to create it was succeeding, it wasn't showing up in the list on the next run. I probably created it 20 times in the course of 15 minutes? Then I started seeing the playlist appear many times in the web UI. Looks like there is some latency is the back end before the new playlist propagates through. Also, I'm not sure there were as many dupe playlists that showed up as the ones that were created.

This morning I didn't get the limit error, so maybe the block is about 12-24 hours?

I ran the create once, and after 15-20 minutes, I still don't see the playlist in the web UI...

<!-- gh-comment-id:629828091 --> @beville commented on GitHub (May 17, 2020): I don't have a solid idea of the limit. I was testing a function that takes a playlist title, searches the results of get_library_playlists() for that then, and then creates the playlist it if title is missing. Even though the call to create it was succeeding, it wasn't showing up in the list on the next run. I probably created it 20 times in the course of 15 minutes? Then I started seeing the playlist appear many times in the web UI. Looks like there is some latency is the back end before the new playlist propagates through. Also, I'm not sure there were as many dupe playlists that showed up as the ones that were created. This morning I didn't get the limit error, so maybe the block is about 12-24 hours? I ran the create once, and after 15-20 minutes, I still don't see the playlist in the web UI...
Author
Owner

@sigma67 commented on GitHub (May 18, 2020):

I've noticed the latency after creating a playlist as well. This has only started happening recently, indicating that probably something on YouTube's end has changed

It's strange because it doesn't happen when it's created using the web UI. Need to do some thorough testing to figure out the cause

<!-- gh-comment-id:630077414 --> @sigma67 commented on GitHub (May 18, 2020): I've noticed the latency after creating a playlist as well. This has only started happening recently, indicating that probably something on YouTube's end has changed It's strange because it doesn't happen when it's created using the web UI. Need to do some thorough testing to figure out the cause
Author
Owner

@beville commented on GitHub (May 18, 2020):

As I was playing around yesterday, I noticed that when I called create_playlist() and passed a track list, the new playlist never showed up, even though I got a new ID. But when I called create_playlist() and didn't pass a playlist, and right after called add_playlist_items(), I would see the new playlist within a few minutes.

<!-- gh-comment-id:630249819 --> @beville commented on GitHub (May 18, 2020): As I was playing around yesterday, I noticed that when I called create_playlist() and passed a track list, the new playlist never showed up, even though I got a new ID. But when I called create_playlist() and _didn't_ pass a playlist, and right after called add_playlist_items(), I would see the new playlist within a few minutes.
Author
Owner

@sigma67 commented on GitHub (May 18, 2020):

You're correct, this seems to be a restriction on YouTube's end. I verified this on the Web UI:

  • create a new playlist from the context menu of an existing playlist/album
  • it will only show up in your library with several minutes of delay
<!-- gh-comment-id:630263348 --> @sigma67 commented on GitHub (May 18, 2020): You're correct, this seems to be a restriction on YouTube's end. I verified this on the Web UI: - create a new playlist from the context menu of an existing playlist/album - it will only show up in your library with several minutes of delay
Author
Owner

@beville commented on GitHub (May 18, 2020):

Ha, I just went to YTM site now, and all the 'lost' empty playlists from this weekend have shown up! So weird.

Once I saw there were issues, I started putting a timestamp string into the description. Some that I created Saturday afternoon appeared after Sunday night!

<!-- gh-comment-id:630269360 --> @beville commented on GitHub (May 18, 2020): Ha, I just went to YTM site now, and all the 'lost' empty playlists from this weekend have shown up! So weird. Once I saw there were issues, I started putting a timestamp string into the description. Some that I created Saturday afternoon appeared after Sunday night!
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#14
No description provided.