[GH-ISSUE #760] YTMusic.create_playlist raises Exception #488

Closed
opened 2026-02-27 23:01:04 +03:00 by kerem · 1 comment
Owner

Originally created by @PriyanshVerma on GitHub (Apr 6, 2025).
Original GitHub issue: https://github.com/sigma67/ytmusicapi/issues/760

system: MacOS ARM
browser: chrome
purpose: migrating my spotify playlist to ytmusic

I'm unable to debug why the call to _send_request in the YTMusic.create_playlist function fails with the exception

Exception: Server returned HTTP 400: Bad Request.
Request contains an invalid argument.
  • The invocation on my end is simple:
    ytmusic.create_playlist('name', 'desc')
  • the playlist has only 83 songs so size cant be an issue

While there are plenty check_auth() calls in the library's functions, I still have a feeling that this failing must have something to do with the oauth creds (happy to be proved wrong though!).
On my part, I followed all steps related to authentication using oauth, listed here:

  1. Creation of oauth.json by following the output of the command ytmusicapi oauth
  2. Creation of TVs and Limited Input devices creds on Google API console and using them in the YTMusic ctor.

The oauth.json created is of the form:

{
"scope": "https://www.googleapis.com/auth/youtube",
"token_type": "Bearer",
"access_token": "token",
"refresh_token": "token",
"expires_at": 1744036993,
"expires_in": 81400
}

Note that:

  • I had to update the code from from ytmusicapi import OAuthCredentials (as given in the doc examples)
    to ytmusicapi.auth.oauth import OAuthCredentials (based on file navigation, tbh i think documentation here is out of date)
  • I tried to use alternate forms of credential json (the project documentation mentions various ways!) like browser, etc but they seem a bit clunky with some not working on the terminal (even via pbaste) and others giving an unauth exception. The OAuth one seems the most straightforward.

This is the full stack trace:

File "/Users/priyanshverma/Documents/Upskill/Coding/Projects/spotify_to_ytmusic/main.py", line 67, in
main()
File "/Users/priyanshverma/Documents/Upskill/Coding/Projects/spotify_to_ytmusic/main.py", line 63, in main
added, failed = add_tracks_to_ytmusic(ytm, sp_tracks)
File "/Users/priyanshverma/Documents/Upskill/Coding/Projects/spotify_to_ytmusic/main.py", line 39, in add_tracks_to_ytmusic
yt_playlist_id = ytmusic.create_playlist("AlternateVersions", "ImportedfromSpotify")
File "/Users/priyanshverma/.pyenv/versions/3.8.10/envs/pydrive-experiment/lib/python3.8/site-packages/ytmusicapi/mixins/playlists.py", line 323, in create_playlist
response = self._send_request(endpoint, body)
File "/Users/priyanshverma/.pyenv/versions/3.8.10/envs/pydrive-experiment/lib/python3.8/site-packages/ytmusicapi/ytmusic.py", line 241, in _send_request
raise Exception(message + error)
Exception: Server returned HTTP 400: Bad Request.
Request contains an invalid argument.

Code sample

def add_tracks_to_ytmusic(ytmusic, sp_tracks):
    ytmusic._check_auth()
    yt_playlist_id = ytmusic.create_playlist("AlternateVersions", "ImportedfromSpotify")

where ytmusic is created like so:

from ytmusicapi import YTMusic
from ytmusicapi.auth.oauth import OAuthCredentials

def setup_ytm():
    google_client_id = 'obtained from google dev console'
    google_client_sec = 'obtained from google dev console'
    return YTMusic('full/path/to/oauth.json', 
                   oauth_credentials=OAuthCredentials(client_id=google_client_id, client_secret=google_client_sec))

I'm hesitant to use your other module spotify_to_ytmusic (which is what I'm building myself) because it seems to use the same underlying code, and since it's failing for me here, it might as well fail there!

Any inputs are greatly appreciated, and thanks for this library!

Originally created by @PriyanshVerma on GitHub (Apr 6, 2025). Original GitHub issue: https://github.com/sigma67/ytmusicapi/issues/760 system: MacOS ARM browser: chrome purpose: migrating my spotify playlist to ytmusic I'm unable to debug why the call to `_send_request` in the `YTMusic.create_playlist` function fails with the exception ``` Exception: Server returned HTTP 400: Bad Request. Request contains an invalid argument. ``` - The invocation on my end is simple: `ytmusic.create_playlist('name', 'desc')` - the playlist has only 83 songs so size cant be an issue While there are plenty check_auth() calls in the library's functions, I still have a feeling that this failing must have something to do with the oauth creds (happy to be proved wrong though!). On my part, I followed all steps related to authentication using oauth, listed [here](https://ytmusicapi.readthedocs.io/en/stable/setup/oauth.html): 1. Creation of oauth.json by following the output of the command `ytmusicapi oauth` 2. Creation of TVs and Limited Input devices creds on Google API console and using them in the YTMusic ctor. The oauth.json created is of the form: > { > "scope": "https://www.googleapis.com/auth/youtube", > "token_type": "Bearer", > "access_token": "token", > "refresh_token": "token", > "expires_at": 1744036993, > "expires_in": 81400 > } Note that: - I had to update the code from `from ytmusicapi import OAuthCredentials` (as given in the doc examples) to `ytmusicapi.auth.oauth import OAuthCredentials` (based on file navigation, tbh i think documentation here is out of date) - I tried to use alternate forms of credential json (the project documentation mentions various ways!) like browser, etc but they seem a bit clunky with some not working on the terminal (even via pbaste) and others giving an unauth exception. The OAuth one seems the most straightforward. This is the full stack trace: > File "/Users/priyanshverma/Documents/Upskill/Coding/Projects/spotify_to_ytmusic/main.py", line 67, in <module> > main() > File "/Users/priyanshverma/Documents/Upskill/Coding/Projects/spotify_to_ytmusic/main.py", line 63, in main > added, failed = add_tracks_to_ytmusic(ytm, sp_tracks) > File "/Users/priyanshverma/Documents/Upskill/Coding/Projects/spotify_to_ytmusic/main.py", line 39, in add_tracks_to_ytmusic > yt_playlist_id = ytmusic.create_playlist("AlternateVersions", "ImportedfromSpotify") > File "/Users/priyanshverma/.pyenv/versions/3.8.10/envs/pydrive-experiment/lib/python3.8/site-packages/ytmusicapi/mixins/playlists.py", line 323, in create_playlist > response = self._send_request(endpoint, body) > File "/Users/priyanshverma/.pyenv/versions/3.8.10/envs/pydrive-experiment/lib/python3.8/site-packages/ytmusicapi/ytmusic.py", line 241, in _send_request > raise Exception(message + error) > Exception: Server returned HTTP 400: Bad Request. > Request contains an invalid argument. Code sample ``` def add_tracks_to_ytmusic(ytmusic, sp_tracks): ytmusic._check_auth() yt_playlist_id = ytmusic.create_playlist("AlternateVersions", "ImportedfromSpotify") ``` where ytmusic is created like so: ``` from ytmusicapi import YTMusic from ytmusicapi.auth.oauth import OAuthCredentials def setup_ytm(): google_client_id = 'obtained from google dev console' google_client_sec = 'obtained from google dev console' return YTMusic('full/path/to/oauth.json', oauth_credentials=OAuthCredentials(client_id=google_client_id, client_secret=google_client_sec)) ``` I'm hesitant to use your other module spotify_to_ytmusic (which is what I'm building myself) because it seems to use the same underlying code, and since it's failing for me here, it might as well fail there! Any inputs are greatly appreciated, and thanks for this library!
kerem closed this issue 2026-02-27 23:01:05 +03:00
Author
Owner

@sigma67 commented on GitHub (Apr 17, 2025):

I am unable to follow your issue - the create_playlist API is working fine as always.

<!-- gh-comment-id:2813045408 --> @sigma67 commented on GitHub (Apr 17, 2025): I am unable to follow your issue - the create_playlist API is working fine as always.
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#488
No description provided.