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
71.14k stars 29.82k forks source link

HTTP Error for GET to https://api.spotify.com/v1/me/player with Params... #123452

Open rwjack opened 1 month ago

rwjack commented 1 month ago

The problem

Logger: spotipy.client
Source: components/spotify/media_player.py:415
First occurred: 12:18:53 PM (1 occurrences)
Last logged: 12:18:53 PM

HTTP Error for GET to https://api.spotify.com/v1/me/player with Params: {'market': None, 'additional_types': [<MediaType.EPISODE: 'episode'>]} returned 401 due to None

Unsure what caused this. Regular music playback seems to work.

What version of Home Assistant Core has the issue?

core-2024.8.0

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

No response

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 1 month 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)

smarthomefamilyverrips commented 1 month ago

Logger: spotipy.client Source: components/spotify/media_player.py:415 First occurred: 12:30:00 (1 occurrences) Last logged: 12:30:00

HTTP Error for GET to https://api.spotify.com/v1/me/player with Params: {'market': None, 'additional_types': [<MediaType.EPISODE: 'episode'>]} returned 401 due to None

Same happens to me, started few days ago without having made any changes, I am on HA 2024.7.3

pyrker commented 1 month ago

same, on HA 2024.7.4

postaccountgh commented 1 month ago

Same here with 2024.7.4

erkr commented 1 month ago

Spotify is phasing out old username/password authorisation. Maybe this issue is related https://github.com/librespot-org/librespot/issues/1308#issuecomment-2276196094

smarthomefamilyverrips commented 1 month ago

Spotify is phasing out old username/password authorisation. Maybe this issue is related librespot-org/librespot#1308 (comment)

@erkr but i followed the config flow of integration page and use client id and secret, then I would say as a rookie why would username/password changes affect this?

erkr commented 1 month ago

Just depends if this integration used librespot.

smarthomefamilyverrips commented 1 month ago

@erkr No idea I just use the build in spotify integration of HA core

joostlek commented 1 month ago

@erkr we use Spotify. I'm not sure where this comes from tbh. I'm assuming that this is because of a flakey service at Spotify

smarthomefamilyverrips commented 1 month ago

I not know if helps but at me at same time when I get the same error message as the OP I also get this error message

Logger: homeassistant.helpers.entity Source: helpers/entity.py:944 First occurred: 11:10:34 (18 occurrences) Last logged: 17:43:06

Update for media_player.spotify_sesamemadness_2 fails Traceback (most recent call last): File "/usr/local/lib/python3.12/site-packages/spotipy/client.py", line 271, in _internal_call response.raise_for_status() File "/usr/local/lib/python3.12/site-packages/requests/models.py", line 1024, in raise_for_status raise HTTPError(http_error_msg, response=self) requests.exceptions.HTTPError: 401 Client Error: Unauthorized for url: https://api.spotify.com/v1/me/player?additional_types=episode

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/components/spotify/media_player.py", line 98, in wrapper result = func(self, *args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/components/spotify/media_player.py", line 415, in update current = self.data.client.current_playback( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/spotipy/client.py", line 1757, in current_playback return self._get("me/player", market=market, additional_types=additional_types) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/spotipy/client.py", line 323, in _get return self._internal_call("GET", url, payload, kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/spotipy/client.py", line 293, in _internal_call raise SpotifyException( spotipy.exceptions.SpotifyException: http status: 401, code:-1 - https://api.spotify.com/v1/me/player?additional_types=episode: None, reason: None

The above exception was the direct cause of the following exception:

Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 944, in async_update_ha_state await self.async_device_update() File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1298, in async_device_update await hass.async_add_executor_job(self.update) File "/usr/local/lib/python3.12/concurrent/futures/thread.py", line 58, in run result = self.fn(*self.args, **self.kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/components/spotify/media_player.py", line 106, in wrapper raise HomeAssistantError(f"Spotify error: {exc.reason}") from exc homeassistant.exceptions.HomeAssistantError: Spotify error: None

joostlek commented 1 month ago

It's the same

erkr commented 1 month ago

@joostlek librespot is impacted by removal of username/password logins in Spotify (used by e.g music assistant). You are using spotipy, which seems to use Oauth, which should be fine, so ignore my remark 🫣

hmmbob commented 1 month ago

@erkr we use Spotify. I'm not sure where this comes from tbh. I'm assuming that this is because of a flakey service at Spotify

Not sure if flaky or just no longer valid. Logs have been filling up for every SPotify account in my HA with the following:

2024-08-12 07:59:52.507 ERROR (SyncWorker_44) [spotipy.client] HTTP Error for GET to https://api.spotify.com/v1/me/player with Params: {'market': None, 'additional_types': [<MediaType.EPISODE: 'episode'>]} returned 401 due to None

and

requests.exceptions.HTTPError: 401 Client Error: Unauthorized for url: https://api.spotify.com/v1/me/player?additional_types=episode

looks like something might have changed around episodes?

joostlek commented 1 month ago

It's not specifically episodes, that's just us telling to the API we support podcasts in the response.

dancavallaro commented 1 month ago

I'm seeing this error as well -- if it helps, I've only started seeing this error after upgrading from HA 2024.1.6 to 2024.8 (I'm running the container, in Docker, on Debian 12).

It doesn't seem to be a fatal error, or at least, it doesn't seem to impact most of my Spotify usage -- I have an automation that plays a playlist, and an automation that plays a song, and they both seem to generally be working fine.

Please let me know if there's any additional information that might help.

dancavallaro commented 1 month ago

One other thing I've noticed is that all of these errors that I've seen always seem to be in relation to Sonos, and particularly this media_player.spotify_sonos entity, e.g.:

2024-08-12 09:55:59.326 ERROR (SyncWorker_2) [spotipy.client] HTTP Error for GET to https://api.spotify.com/v1/me/player/devices with Params: {} returned 401 due to None
2024-08-12 09:55:59.327 ERROR (MainThread) [homeassistant.components.spotify] Error fetching Sonos Devices data:
2024-08-12 09:59:59.297 ERROR (SyncWorker_2) [spotipy.client] HTTP Error for GET to https://api.spotify.com/v1/me/player with Params: {'market': None, 'additional_types': [<MediaType.EPISODE: 'episode'>]} returned 401 due to None
2024-08-12 09:59:59.298 ERROR (MainThread) [homeassistant.helpers.entity] Update for media_player.spotify_sonos fails
Traceback (most recent call last):
  File "/usr/local/lib/python3.12/site-packages/spotipy/client.py", line 271, in _internal_call
    response.raise_for_status()
  File "/usr/local/lib/python3.12/site-packages/requests/models.py", line 1024, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 401 Client Error: Unauthorized for url: https://api.spotify.com/v1/me/player?additional_types=episode

I have ~10 Sonos speakers integrated with HA and Spotify, and they all seem to be working in my testing, it's just this media_player.spotify_sonos entity that I'm seeing these errors for.

rwjack commented 2 weeks ago

not sure if there were any changes, but I stopped getting this Error

dancavallaro commented 2 weeks ago

not sure if there were any changes, but I stopped getting this Error

Same here. I haven't seen any of these errors since August 13th, and I have not made any changes on my side in the meantime (same HA container image version, in fact, I haven't even recreated the container since then).

pyrker commented 2 weeks ago

The errors are back again, and it's worse, this time it is not possible to control the player anymore. Logs say: "No active device found". I even tried resetting the homeassistant Spotify integration (deleted it, set it up new).

Logger: spotipy.client
Quelle: components/spotify/media_player.py:318
HTTP Error for PUT to https://api.spotify.com/v1/me/player/pause with Params: {} returned 404 due to Player command failed: No active device found

Logger: homeassistant.components.websocket_api.http.connection
Quelle: components/websocket_api/commands.py:241
Integration: Home Assistant WebSocket API ([Dokumentation](https://www.home-assistant.io/integrations/websocket_api), [Probleme](https://github.com/home-assistant/core/issues?q=is%3Aissue+is%3Aopen+label%3A%22integration%3A+websocket_api%22))
Erstmals aufgetreten: 18:27:12 (1 Vorkommnisse)
Zuletzt protokolliert: 18:27:12

[140349711566304] Unexpected exception
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/websocket_api/commands.py", line 241, in handle_call_service
    response = await hass.services.async_call(
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/core.py", line 2763, in async_call
    response_data = await coro
                    ^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/core.py", line 2806, in _execute_service
    return await target(service_call)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 999, in entity_service_call
    single_response = await _handle_entity_call(
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 1071, in _handle_entity_call
    result = await task
             ^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/media_player/__init__.py", line 822, in async_media_pause
    await self.hass.async_add_executor_job(self.media_pause)
  File "/usr/local/lib/python3.12/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/spotify/media_player.py", line 105, in wrapper
    raise HomeAssistantError("No active playback device found") from None
homeassistant.exceptions.HomeAssistantError: No active playback device found