Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hitting an API rate limit raises KeyError from create_playlist() #19

Closed
beville opened this issue May 16, 2020 · 6 comments
Closed

Hitting an API rate limit raises KeyError from create_playlist() #19

beville opened this issue May 16, 2020 · 6 comments

Comments

@beville
Copy link

beville commented May 16, 2020

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.

@sigma67
Copy link
Owner

sigma67 commented 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.

@beville
Copy link
Author

beville commented 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...

@sigma67
Copy link
Owner

sigma67 commented 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

@beville
Copy link
Author

beville commented 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.

@sigma67
Copy link
Owner

sigma67 commented 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

@beville
Copy link
Author

beville commented 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 up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants