core icon indicating copy to clipboard operation
core copied to clipboard

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

Open rwjack opened this issue 1 year ago • 18 comments

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

rwjack avatar Aug 09 '24 11:08 rwjack

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)

home-assistant[bot] avatar Aug 09 '24 11:08 home-assistant[bot]

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

smarthomefamilyverrips avatar Aug 10 '24 10:08 smarthomefamilyverrips

same, on HA 2024.7.4

pyrker avatar Aug 10 '24 10:08 pyrker

Same here with 2024.7.4

postaccountgh avatar Aug 11 '24 05:08 postaccountgh

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

erkr avatar Aug 11 '24 07:08 erkr

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?

smarthomefamilyverrips avatar Aug 11 '24 08:08 smarthomefamilyverrips

Just depends if this integration used librespot.

erkr avatar Aug 11 '24 12:08 erkr

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

smarthomefamilyverrips avatar Aug 11 '24 12:08 smarthomefamilyverrips

@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

joostlek avatar Aug 11 '24 12:08 joostlek

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

smarthomefamilyverrips avatar Aug 11 '24 14:08 smarthomefamilyverrips

It's the same

joostlek avatar Aug 11 '24 14:08 joostlek

@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 🫣

erkr avatar Aug 11 '24 15:08 erkr

@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?

hmmbob avatar Aug 12 '24 06:08 hmmbob

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

joostlek avatar Aug 12 '24 06:08 joostlek

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 avatar Aug 12 '24 13:08 dancavallaro

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.

dancavallaro avatar Aug 12 '24 14:08 dancavallaro

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

rwjack avatar Aug 28 '24 11:08 rwjack

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).

dancavallaro avatar Aug 28 '24 12:08 dancavallaro

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

pyrker avatar Aug 29 '24 16:08 pyrker

I'm now seeing HTTP Error for GET to https://api.spotify.com/v1/me/player/devices returned 401 due to Permissions missing in the logs.

This seems to be related to application scopes.

I removed the service and re-added it, and now I have the following in the logs:

spotify: Error on device update!
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 724, in _async_add_entity
    await entity.async_device_update(warning=False)
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1302, 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 98, in wrapper
    result = func(self, *args, **kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/spotify/media_player.py", line 411, in update
    current = self.data.client.current_playback(
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: Spotify.current_playback() got an unexpected keyword argument 'additional_types'

This is running HA 2024.9.3 on supervisor 2024.9.1 with HAOS 13.1

proffalken avatar Sep 24 '24 14:09 proffalken

Please try again in 2024.11 as last release contained a major refactor

joostlek avatar Nov 11 '24 13:11 joostlek

There hasn't been any activity on this issue recently. Due to the high number of incoming GitHub notifications, we have to clean some of the old issues, as many of them have already been resolved with the latest updates. Please make sure to update to the latest Home Assistant version and check if that solves the issue. Let us know if that works for you by adding a comment 👍 This issue has now been marked as stale and will be closed if no further activity occurs. Thank you for your contributions.

Apologies, I completely missed the updates on here. I can confirm this is now working for me in the latest versions of HA

proffalken avatar Jan 06 '25 11:01 proffalken

👍🏻

joostlek avatar Jan 06 '25 11:01 joostlek