spotcast: 400 error on login.
Have tested creds on spotify web player as well as spotify dev portal, but still getting the following error:
“400 Client Error: Bad Request for url: https://accounts.spotify.com/api/login”
configuration in configuration.yaml is:
spotcast:
username: !secret spotify_username
password: !secret spotify_password
accounts:
alan:
username: !secret spotify_username
password: !secret spotify_password
Have tried with and without the accounts: section. Made sure both secrets and config don’t contain any leading/trailing spaces or other characters.
Running hass.io .108.9 and spotcast 2.91 (says 2.92 is available but requires hass .109 (which isn’t available yet). Ubuntu 18.04 on NUC.
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 8
- Comments: 33 (10 by maintainers)
Commits related to this issue
- TMP add spotcast integration API responds with 400 due to https://github.com/fondberg/spotcast/issues/84 — committed to pkissling/home-assistant by deleted user 4 years ago
- TMP add spotcast integration API responds with 400 due to https://github.com/fondberg/spotcast/issues/84 — committed to pkissling/home-assistant by deleted user 4 years ago
It seems like a dead end with the current way to obtain an access_token since it would require bypassing Google Recaptcha.
I’ve hacked together a potential workaround. Instead of using username and password to obtain a token, I instead use two cookies that are set just after logging in called
sp_dcandsp_key. It does require a manual step to obtain these cookies and they are valid for 1 year. Spotify use them to refresh the access token when it expires after 1 hour.You can checkout how to obtain the access token with the cookies here. https://github.com/petergp/spotify-webplayer-token/blob/master/spotify_token.py
I’ll be testing this the next couple of days. You can find a working fork here: https://github.com/petergp/spotcast/
To obtain the cookies manually: • Open https://accounts.spotify.com/en/login • Open network developer tools in your browser (might require developer menu to be enabled) • Login to Spotify and select Web Player • Search/Filter for
get_access_tokenon the network list in Developer tools • Under cookies for the request findsp_dcandsp_key.Add these to your
configuration.yamlHow long do the web tokens last?
Could one use manual steps to generate a token via a browser login and then store that rather?
Released v3.0.0
I am able to get the sensor with the correct Chromecast devices, but when I call, and this could be user error, I am getting this error:
Failed to call service spotcast/start. Exceeded 30 redirects.
Edit: Bad Copy from the cookies inspector. Works great! Thank you!
Thanks for the feedback everyone!
Lets move forward with getting an official release out. I’ve created a PR for spotify-webplayer-token with the required fixes. Lets see if they want to go this direction, otherwise I’ll remove that dependency and add the new method directly in this repo.
It seems like if you create your own app in the developer dashboard in spotify you can generate a token. I override the get_access_token method and I have the component working at the moment.
Will try to find a nicer solution…
@sermayoral Thanks! I forgot to restart HA after removing the old integration. Now it works!!!
@rtirelli
sp_dcandsp_keyare both cookies that are a part of the request (not the response) of that call.sounds promising! I’ll try and report back as soon as I have time.