home-assistant / core

:house_with_garden: Open source home automation that puts local control and privacy first.
https://www.home-assistant.io
Apache License 2.0
74.07k stars 31.09k forks source link

Spotify: Unexpected error fetching spotify data #131624

Open syphernl opened 4 days ago

syphernl commented 4 days ago

The problem

image

"unexpected character: line 1 column 1 (char 0)"

What version of Home Assistant Core has the issue?

2024.11.3

What was the last working version of Home Assistant Core?

No response

What type of installation are you running?

Home Assistant OS

Integration causing the issue

Spotify

Link to integration documentation on our website

https://www.home-assistant.io/integrations/spotify/

Diagnostics information

2024-11-26 14:30:31.898 ERROR (MainThread) [homeassistant.components.spotify.coordinator] Unexpected error fetching spotify data
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 382, in _async_refresh
    self.data = await self._async_update_data()
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/spotify/coordinator.py", line 119, in _async_update_data
    self._playlist = await self.client.get_playlist(context.uri)
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/spotifyaio/spotify.py", line 428, in get_playlist
    return Playlist.from_json(response)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<string>", line 3, in __mashumaro_from_json__
orjson.JSONDecodeError: unexpected character: line 1 column 1 (char 0)
2024-11-26 14:30:31.900 DEBUG (MainThread) [homeassistant.components.spotify.coordinator] Finished fetching spotify data in 0.144 seconds (success: False)

Example YAML snippet

No response

Anything in the logs that might be useful for us?

No response

Additional information

No response

home-assistant[bot] commented 4 days ago

Hey there @frenck, @joostlek, mind taking a look at this issue as it has been labeled with an integration (spotify) you are listed as a code owner for? Thanks!

Code owner commands Code owners of `spotify` can trigger bot actions by commenting: - `@home-assistant close` Closes the issue. - `@home-assistant rename Awesome new title` Renames the issue. - `@home-assistant reopen` Reopen the issue. - `@home-assistant unassign spotify` Removes the current integration label and assignees on the issue, add the integration domain after the command. - `@home-assistant add-label needs-more-information` Add a label (needs-more-information, problem in dependency, problem in custom component) to the issue. - `@home-assistant remove-label needs-more-information` Remove a label (needs-more-information, problem in dependency, problem in custom component) on the issue.

(message by CodeOwnersMention)


spotify documentation spotify source (message by IssueLinks)

joostlek commented 4 days ago

Can you reproduce this consistently?

syphernl commented 4 days ago

Can you reproduce this consistently?

It happens during startup and when I manually reload the integration (and seems to happen automatically every minute?). I have a feeling my token somehow hit a ratelimit (as it is also being used by Spotcast) and now gets a response from their API this integration cannot handle.

joostlek commented 4 days ago

What playlist are you playing right now? I think it has to do with that

syphernl commented 4 days ago

What playlist are you playing right now? I think it has to do with that

I am playing that "magic playlist" that changes every few hours.

But it seems to me that it is related to ratelimiting. I used the same credentials for Spotcast and due to a bug it hammered the API and probably triggered a ratelimit. I tried re-adding the Spotify integration but it didn't work. The only thing that worked was to remove the application credentials from HASS and to create a new app on the Spotify Developer portal. After that, the Spotify integration started working again.

maxm77-RC commented 1 day ago

I have similar (I think):

Logger: homeassistant.components.spotify.coordinator Source: helpers/update_coordinator.py:382 integration: Spotify (documentation, issues) First occurred: 28 November 2024 at 16:36:40 (79 occurrences) Last logged: 15:07:15

Unexpected error fetching spotify data Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 382, in _async_refresh self.data = await self._async_update_data() ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/components/spotify/coordinator.py", line 97, in _async_update_data audio_features = await self.client.get_audio_features(item.uri) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/spotifyaio/spotify.py", line 518, in get_audio_features return AudioFeatures.from_json(response) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "", line 7, in mashumaro_from_json mashumaro.exceptions.MissingField: Field "danceability" of type float is missing in AudioFeatures instance

frostworx commented 1 day ago

I've just found that "Spotify has shut down several API endpoints" via ycombinator

(see also this other issue)