spotify_to_ytmusic icon indicating copy to clipboard operation
spotify_to_ytmusic copied to clipboard

Exception: Server returned HTTP 400: Bad Request.

Open djlivooo opened this issue 1 year ago • 8 comments

Hello, people. This happens to me when I'm moving a playlist from Spotify to Youtube Music. Is there any solution?

Traceback (most recent call last): File "", line 198, in _run_module_as_main File "", line 88, in run_code File "C:\Users\varga\AppData\Local\Programs\Python\Python312\Scripts\spotify_to_ytmusic.exe_main.py", line 7, in File "C:\Users\varga\AppData\Local\Programs\Python\Python312\Lib\site-packages\spotify_to_ytmusic\main.py", line 86, in main args.func(args) File "C:\Users\varga\AppData\Local\Programs\Python\Python312\Lib\site-packages\spotify_to_ytmusic\controllers.py", line 71, in create _create_ytmusic(args, playlist, ytmusic) File "C:\Users\varga\AppData\Local\Programs\Python\Python312\Lib\site-packages\spotify_to_ytmusic\controllers.py", line 62, in _create_ytmusic playlistId = ytmusic.create_playlist( ^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\varga\AppData\Local\Programs\Python\Python312\Lib\site-packages\spotify_to_ytmusic\ytmusic.py", line 21, in create_playlist return self.api.create_playlist(name, info, privacy, video_ids=tracks) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\varga\AppData\Local\Programs\Python\Python312\Lib\site-packages\ytmusicapi\mixins\playlists.py", line 226, in create_playlist response = self._send_request(endpoint, body) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\varga\AppData\Local\Programs\Python\Python312\Lib\site-packages\ytmusicapi\ytmusic.py", line 156, in _send_request raise Exception(message + error) Exception: Server returned HTTP 400: Bad Request. Request contains an invalid argument.

djlivooo avatar Nov 11 '23 01:11 djlivooo

It's probably a problem with the way you set up your credentials. Which setup method did you use? Can you check your settings.ini file?

sigma67 avatar Nov 11 '23 13:11 sigma67

It's probably a problem with the way you set up your credentials. Which setup method did you use? Can you check your settings.ini file?

Use the method as instructed in the Github First I made the Spotify dashboard. The redirect link is the one from http://localhost. And then I did the authorization by Google OAuth. Although I don't know if that is created automatically or where it is created?

djlivooo avatar Nov 11 '23 16:11 djlivooo

If you did everything correctly it should probably work. To troubleshoot you need to manually inspect the settings.ini file, which is created automatically.

It should be in platformdirs.user_cache_dir/spotify_to_ytmusic, depends on your platform where that is

sigma67 avatar Nov 13 '23 09:11 sigma67

I am having the same issue as djlivooo To be fair the playlist has 1002 tracks in it, another playlist transfered fine before I tried the large playlist I tried to transfer the larger one a second time and it worked.

Anyway I tried to find the settings.ini file you mentioned, I could find the example ini file but not the ehm "real" one? I use scoop to install applications and used it to install python so it seems it saves installed python packages in its folder structure. C:\Users\Clovis\scoop\apps\python\current\Lib\site-packages\spotify_to_ytmusic

Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "C:\Users\Clovis\scoop\apps\python\current\Scripts\spotify_to_ytmusic.exe\__main__.py", line 7, in <module>
  File "C:\Users\Clovis\scoop\apps\python\current\Lib\site-packages\spotify_to_ytmusic\main.py", line 86, in main
    args.func(args)
  File "C:\Users\Clovis\scoop\apps\python\current\Lib\site-packages\spotify_to_ytmusic\controllers.py", line 71, in create
    _create_ytmusic(args, playlist, ytmusic)
  File "C:\Users\Clovis\scoop\apps\python\current\Lib\site-packages\spotify_to_ytmusic\controllers.py", line 60, in _create_ytmusic
    videoIds = ytmusic.search_songs(playlist["tracks"])
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Clovis\scoop\apps\python\current\Lib\site-packages\spotify_to_ytmusic\ytmusic.py", line 32, in search_songs
    result = self.api.search(query)
             ^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Clovis\scoop\apps\python\current\Lib\site-packages\ytmusicapi\mixins\search.py", line 165, in search
    response = self._send_request(endpoint, body)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Clovis\scoop\apps\python\current\Lib\site-packages\ytmusicapi\ytmusic.py", line 151, in _send_request
    response_text = json.loads(response.text)
                    ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Clovis\scoop\apps\python\current\Lib\json\__init__.py", line 346, in loads
    return _default_decoder.decode(s)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Clovis\scoop\apps\python\current\Lib\json\decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Clovis\scoop\apps\python\current\Lib\json\decoder.py", line 355, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

Lod3 avatar Nov 27 '23 10:11 Lod3

@Lod3 the settings file should be in %APPDATA%/spotify_to_ytmusic

sigma67 avatar Jan 22 '24 11:01 sigma67

I'm consistently seeing this with trying to import https://open.spotify.com/playlist/3YgiYNSYXeKWPkcVKZY4xc - it is a rather large playlist with thousands of entries, so that seems to match with the original report. I've successfully imported a far smaller one, so I believe my config should be right. I've not yet had the time to investigate further than this, but I thought I'd provide what is (to me) a consistent reproduction of these symptoms.

turmoni avatar Feb 08 '24 12:02 turmoni

Maybe the issue is that too many videos are being passed to create_playlist.

YouTube's playlist limit is at 5000: https://webapps.stackexchange.com/questions/77790/what-is-the-maximum-youtube-playlist-length

so it is in fact impossible to transfer this playlist. Could implement an exception for this case

sigma67 avatar Feb 08 '24 12:02 sigma67

Ah, I was wondering if there was some kind of API limit, I hadn't considered that there would just be a playlist size limit, thanks

turmoni avatar Feb 17 '24 11:02 turmoni