spotcast: Token request for spotcast failed (invalid_grant): Refresh token revoked
Outage Acknowledgement
- I confirm that I have read issue #543 and this report is not related to the current outage.
The problem
After installing version v6.0.0-a3 everything worked as it should. I think it’s a very good way to restore the application’s functionality. After restarting Home Assistant, a token error appeared.
I removed the “service” from my Spotify account and tried to add it again with the old Access and Refresh Tokens but it didn’t work. With the newly generated tokens, I managed to add the service and everything works as it should again.
Spotify doesn’t include something like “remember me” in the login window.
System Health details
Wersja | core-2025.5.2 Installation type | Home Assistant OS Development | false Supervisor | true Docker | true Użytkownik | root Virtual environment | false Python version | 3.13.3 Operating system family | Linux Operating system version | 6.12.23-haos CPU architecture | x86_64 Strefa czasowa | Europe/Warsaw
Spotcast | v6.0.0-a3
What type of installation are you running?
Home Assistant OS
Diagnostics information
Example YAML snippet
Anything in the logs that might be useful for us?
1.
Rejestrator: custom_components.spotcast.sessions.desktop_session
Źródło: custom_components/spotcast/sessions/desktop_session.py:136
integracja: Spotcast (dokumentacja, Problemy)
Pierwsze zdarzenie: 21:22:04 (4 wystąpienia)
Ostatnio zalogowany: 21:23:50
Token request for spotcast failed (invalid_grant): Refresh token revoked
2.
Rejestrator: homeassistant.config_entries
Źródło: config_entries.py:749
Pierwsze zdarzenie: 21:22:04 (4 wystąpienia)
Ostatnio zalogowany: 21:23:50
Error setting up entry Krzysztof for spotcast
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/config_entries.py", line 749, in __async_setup_with_context
result = await component.async_setup_entry(hass, self)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/config/custom_components/spotcast/__init__.py", line 51, in async_setup_entry
account = await SpotifyAccount.async_from_config_entry(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
...<2 lines>...
)
^
File "/config/custom_components/spotcast/spotify/account.py", line 1279, in async_from_config_entry
await private_session.async_ensure_token_valid()
File "/config/custom_components/spotcast/sessions/desktop_session.py", line 89, in async_ensure_token_valid
api_response = await self.async_refresh_token()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/config/custom_components/spotcast/sessions/desktop_session.py", line 143, in async_refresh_token
response.raise_for_status()
~~~~~~~~~~~~~~~~~~~~~~~~~^^
File "/usr/local/lib/python3.13/site-packages/aiohttp/client_reqrep.py", line 1161, in raise_for_status
raise ClientResponseError(
...<5 lines>...
)
aiohttp.client_exceptions.ClientResponseError: 400, message='Bad Request', url='https://accounts.spotify.com/api/token'
Additional information
No response
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 54
Commits related to this issue
- fix for #552. Fixed race condition in saving credentials — committed to fondberg/spotcast by fcusson a year ago
- potential fix for #552 edgecases for save to disk config entry — committed to fondberg/spotcast by fcusson a year ago
Just released
v6.0.0-a8that should fix the refresh token revoke error. I have been testing on my local container this evening and data looks to be saving properly now.Released Build 10. I tested this one over the span of 2 days with multiple hours between the reboot including letting it run the whole night and rebooting the next morning. All reboot have been successful at this point.
At the same time, I’m releasing the improved configuration setup. Almost all the setup is done in Home Assistant at this point with only a relay server needed on the local machine. The script is now much simpler and doing a lot less, while relying more on Home Assistant to do the heavy lifting. A link to the new configuration instructions are in the release notes.
I’ll add a warning in the instructions to say that the server must be ready before starting the setup. Also, in the full release There will be an aknowledgement step that will inform the user that they need to run a relay server and direct them to the instructions.
To my defence, if you read the instruction it does say to start the server before starting the configuration in Home Assistant 😬 (But yeah I see why it can be confusing)
@EPiSKiNG if your credentials were still valid, that doesn’t tell us much for the moment, Could you try to reboot tomorrow and confirm if the reboot goes through?
@Mincka, not really, that’s the weird part, its that the save on disk seems unreliable, I have cases of tokens being saved after the initial setup but not always. The behaviour is now different, but still unreliable for the most part.
The issue seems to span from sub dictionaries in
entry.datamutating when what I assumed was copies of them are being updated, but if the dictionary is still a pointer to theentry.datainner dictionary, both get updated. Basically:The issue now, is when calling the
async_update_entry, there is an inner step in the function that checks the new data on the current data inside the entry. If they match, home assistant skips the update of the data. The good news, is that, as long as I make sure something at the root level is for sure different than the current data, it will update the data. My current local builds has alast_updatekey that just pushes the current ISO8601 timestamp in the data dictionary at the root level, this means, inner dictionaries might be mutated, but a new string (immutable) was just pushed in the dictionary, so they are for sure different at this point.I was able to wait for a token refresh and successfully reboot after, so this looks promissing
@Mincka yeah the issue is due to the fact the
SpotifyAccountis created with valid tokens already in its 2 sessions, so if you restart the server after the expiration as you mentioned, the tokens are not saved to disk and you would have to wait for the next expiration for the info to actually get saved. The new version seems to be more resilient. I added a force update entry flag so that when the spotify account is first created at boot, the config entry is forced to update. This might mean writting to disk in cases where it is not necessary (just overwritting the same data), but at least it should fix the issue for the moment.I’ll look into moving the authentication of the tokens from inside the SpotifyAccount creation instead of before on a future build, this will prevent unnecessary right to disk. In the meantime, build 9 is almost released.
@Manazer thats not the same error, yours is
access token expired. This is already reported in #546. Also, the link you provide just points to the new process for spotifyplus used to implement the desktop token, which is exactly what we also implemented in V6.