OAuth is not working. 400 Bad Request error
Closed this issue · 3 comments
Don't have much of an output to show you since I tried to fix this and lost all output from the failure. A bit of tinkering is required. OAuth used was not working for me. Browser authentication worked for me. Just creating this issue so that others who come across this will know what to do.
Create a .py file within your env (if you got one) and then write the ytmusicapi.setup code mentioned here:
https://ytmusicapi.readthedocs.io/en/stable/setup/browser.html
I was on a MAC so I ran the code like this:
pbpaste "raw-request-header-from-a-POST-200-request" | python3 -m yt_browser_auth
Make sure the cookie section of your header has something like this in it "__Secure-3PAPISID="
This should create a browser.json file. Now Navigate to backend.py and under "def get_ytmusic", change the oauth.json to whatever you named your json file to when running the previous script.
Is all. Happy sailing!
Thanks a million for this! You helped me get this working! 🎉
I'm using PIPX (on a mac) to install and run this, so it was a smidge more fiddly. For anyone looking for a verbose step by step, this is the full process I went through to copy a playlist:
Step By Step
-
brew install python python-tk pipx
-
pipx install spotify2ytmusic ytmusicapi && pipx ensurepath
-
Create a working directory somewhere and copy in
spotify-backup
as mention in the readme.cd
in there. -
python3 spotify-backup.py playlists.json --dump=liked,playlists --format=json
-
Follow the YT Music API instructions to copy your YT Music Headers to the clipboard.
-
pbpaste | ytmusicapi browser
-
Edit
~/.local/pipx/venvs/spotify2ytmusic/lib/python3.12/site-packages/spotify2ytmusic/backend.py
as @BOB-THE-BUILDER01 suggested:
# ...
def get_ytmusic() -> YTMusic:
"""
@@@
"""
if not os.path.exists("browser.json"):
print("ERROR: No file 'browser.json' exists in the current directory.")
print(" Have you logged in to YTMusic? Run 'ytmusicapi browser' to login")
sys.exit(1)
try:
return YTMusic("browser.json")
except json.decoder.JSONDecodeError as e:
print(f"ERROR: JSON Decode error while trying start YTMusic: {e}")
print(" This typically means a problem with a 'browser.json' file.")
print(" Have you logged in to YTMusic? Run 'ytmusicapi browser' to login")
sys.exit(1)
-
s2yt_list_playlists
and get the Spotify playlist ID you want to copy -
s2yt_copy_playlist <SPOTIFY_PLAYLIST_ID> "+Name of new YT Music Playlist"
Phew!
Can't help but feel it would be in Google's best interest to offer this sort of import functionality, but they're probably got some agreement with Spotify or something.
Again, so many thank yous!
Damn. Just noticed this: #125 (comment)
Oh wow, I didn't notice it either.
I just kept searching for OAuth errors and I ended up on other threads that use browser authentication.
Anyways, I'll close this issue then.