homeassistantcomponent_spotifyplus: Can't get integration to work reliably. Internal server error and device not found errors

System Health details

System Information

version core-2024.6.4
installation_type Home Assistant Core
dev false
hassio false
docker false
user homeassistant
virtualenv true
python_version 3.12.3
os_name Linux
os_version 6.1.89-15498-gf9afb0b2911b
arch aarch64
timezone America/Detroit
config_dir /home/homeassistant/.homeassistant
Home Assistant Community Store
GitHub API ok
GitHub Content ok
GitHub Web ok
GitHub API Calls Remaining 5000
Installed Version 1.34.0
Stage running
Available Repositories 1392
Downloaded Repositories 4
HACS Data ok
Home Assistant Cloud
logged_in true
subscription_expiration July 17, 2024 at 8:00 PM
relayer_connected true
relayer_region us-east-1
remote_enabled false
remote_connected false
alexa_enabled true
google_enabled true
remote_server us-east-1-12.ui.nabu.casa
certificate_status ready
instance_id 8558a708d8f94f7589c3d170eeb93b0b
can_reach_cert_server ok
can_reach_cloud_auth ok
can_reach_cloud ok
Dashboards
dashboards 3
resources 0
views 1
mode storage
Recorder
oldest_recorder_run June 13, 2024 at 8:36 PM
current_recorder_run June 23, 2024 at 12:23 PM
estimated_db_size 75.62 MiB
database_engine sqlite
database_version 3.40.1
SpotifyPlus
integration_version v1.0.30
clients_configured 1: 1257898300 (premium)
api_endpoint_reachable ok

Checklist

  • I have enabled SmartInspect debug logging for my installation.
  • I have filled out the issue template to the best of my ability.
  • This issue only contains 1 issue (if you have multiple issues, open one issue for each issue).
  • This issue is not a duplicate issue of any previous issues…

Describe the issue

I’m not sure exactly how this integration is supposed to work as far as capability. I know if I set my phone to play spotify on my tv as a device, the tv will open the spotify app automatically. I’m not sure if this integration is able to do this. When I try this sort of use case, I get 500 internal server errors when switching devices in the list, and No active device found errors when trying to play on the selected device. If I start the app on the tv, and it is already selected as the device in the player, then I can play on it without error. Of course if I close the app and try to play again, I get the no active device found errors.

I just want to make sure the integration is functioning as intended. I’ve included examples of the 500 Internal server error when attempting to switch devices, and the no active device errors in the debug logs section.

Reproduction steps

  1. Attempt to switch devices in device list in player when devices are not actively running the spotify app.
  2. Attempt to play spotify on a device in the device list that is already selected or default but is not running the app.

…

Debug logs

Attempt to play on a selected device

2024-06-23 12:44:13.602 WARNING (SyncWorker_0) [spotifywebapipython.spotifyclient] Spotify Connect device name '48b677ca-ef9b-516f-b702-93bf2e8c67ba' could not be resolved; please ensure that the specified device is powered on and available on the local network
2024-06-23 12:44:13.694 DEBUG (SyncWorker_0) [custom_components.spotifyplus] 'SpotifyPlus 1257898300': Processed a media player command - forcing a playerState scan window for the next 5 updates
2024-06-23 12:44:13.695 ERROR (MainThread) [homeassistant.components.websocket_api.http.connection] [281470778407616] Unexpected exception
Traceback (most recent call last):
File "/home/homeassistant/.homeassistant/custom_components/spotifyplus/media_player.py", line 212, in wrapper
result = func(self, *args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/homeassistant/.homeassistant/custom_components/spotifyplus/media_player.py", line 553, in media_play
deviceId:str = self._VerifyDeviceActive()
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/homeassistant/.homeassistant/custom_components/spotifyplus/media_player.py", line 1265, in _VerifyDeviceActive
result:PlayerPlayState = self.data.spotifyClient.PlayerVerifyDeviceDefault(PlayerDevice.GetIdFromSelectItem(self.data.OptionDeviceDefault), False)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/srv/homeassistant/lib/python3.12/site-packages/spotifywebapipython/spotifyclient.py", line 10983, in PlayerVerifyDeviceDefault
self.PlayerTransferPlayback(defaultDeviceId, play, delay)
File "/srv/homeassistant/lib/python3.12/site-packages/spotifywebapipython/spotifyclient.py", line 10884, in PlayerTransferPlayback
self.MakeRequest('PUT', msg)
File "/srv/homeassistant/lib/python3.12/site-packages/spotifywebapipython/spotifyclient.py", line 814, in MakeRequest
msg.ResponseData = self._CheckResponseForErrors(msg, response)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/srv/homeassistant/lib/python3.12/site-packages/spotifywebapipython/spotifyclient.py", line 555, in _CheckResponseForErrors
raise SpotifyWebApiError(errCode, errMessage, msg.MethodName, response.reason, _logsi)
spotifywebapipython.spotifywebapierror.SpotifyWebApiError: SAM1001E - Spotify Web API returned an error status while processing the "PlayerTransferPlayback" method.
Status: 404 - Not Found
Message: "Player command failed: No active device found"
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/srv/homeassistant/lib/python3.12/site-packages/homeassistant/components/websocket_api/commands.py", line 241, in handle_call_service
response = await hass.services.async_call(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/srv/homeassistant/lib/python3.12/site-packages/homeassistant/core.py", line 2741, in async_call
response_data = await coro
^^^^^^^^^^
File "/srv/homeassistant/lib/python3.12/site-packages/homeassistant/core.py", line 2784, in _execute_service
return await target(service_call)
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/srv/homeassistant/lib/python3.12/site-packages/homeassistant/helpers/service.py", line 977, in entity_service_call
single_response = await _handle_entity_call(
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/srv/homeassistant/lib/python3.12/site-packages/homeassistant/helpers/service.py", line 1049, in _handle_entity_call
result = await task
^^^^^^^^^^
File "/srv/homeassistant/lib/python3.12/site-packages/homeassistant/components/media_player/__init__.py", line 818, in async_media_play
await self.hass.async_add_executor_job(self.media_play)
File "/usr/lib/python3.12/concurrent/futures/thread.py", line 58, in run
result = self.fn(*self.args, **self.kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/homeassistant/.homeassistant/custom_components/spotifyplus/media_player.py", line 226, in wrapper
raise HomeAssistantError(ex.Message)
homeassistant.exceptions.HomeAssistantError: Player command failed: No active device found


Switching devices

2024-06-23 12:47:15.130 ERROR (MainThread) [homeassistant.components.websocket_api.http.connection] [281470778407616] Unexpected exception
Traceback (most recent call last):
File "/srv/homeassistant/lib/python3.12/site-packages/spotifywebapipython/spotifyclient.py", line 10870, in PlayerTransferPlayback
deviceId = self.PlayerResolveDeviceId(deviceId, verifyUserContext=True)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/srv/homeassistant/lib/python3.12/site-packages/spotifywebapipython/spotifyclient.py", line 10453, in PlayerResolveDeviceId
zcfResult = zconn.Connect(self._SpotifyConnectUsername, self._SpotifyConnectPassword)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/srv/homeassistant/lib/python3.12/site-packages/spotifywebapipython/zeroconfapi/zeroconfconnect.py", line 358, in Connect
responseData:dict = self._CheckResponseForErrors(response, apiMethodName)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/srv/homeassistant/lib/python3.12/site-packages/spotifywebapipython/zeroconfapi/zeroconfconnect.py", line 249, in _CheckResponseForErrors
raise SpotifyZeroconfApiError(errCode, errMessage, methodName, response.reason, _logsi)
spotifywebapipython.zeroconfapi.spotifyzeroconfapierror.SpotifyZeroconfApiError: SAM1003E - Spotify ZeroConf API returned an error status while processing the "Connect" method.
Status: 500 - Internal Server Error
Message: "Internal Server Error"
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/homeassistant/.homeassistant/custom_components/spotifyplus/media_player.py", line 212, in wrapper
result = func(self, *args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/homeassistant/.homeassistant/custom_components/spotifyplus/media_player.py", line 740, in select_source
self.data.spotifyClient.PlayerTransferPlayback(source, (self.state == MediaPlayerState.PLAYING))
File "/srv/homeassistant/lib/python3.12/site-packages/spotifywebapipython/spotifyclient.py", line 10901, in PlayerTransferPlayback
raise SpotifyApiError(SAAppMessages.UNHANDLED_EXCEPTION.format(apiMethodName, str(ex)), ex, logsi=_logsi)
spotifywebapipython.spotifyapierror.SpotifyApiError: SpotifyApiError: SAM0001E - An unhandled exception occured while processing method "PlayerTransferPlayback".
SAM1003E - Spotify ZeroConf API returned an error status while processing the "Connect" method.
Status: 500 - Internal Server Error
Message: "Internal Server Error"
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/srv/homeassistant/lib/python3.12/site-packages/homeassistant/components/websocket_api/commands.py", line 241, in handle_call_service
response = await hass.services.async_call(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/srv/homeassistant/lib/python3.12/site-packages/homeassistant/core.py", line 2741, in async_call
response_data = await coro
^^^^^^^^^^
File "/srv/homeassistant/lib/python3.12/site-packages/homeassistant/core.py", line 2784, in _execute_service
return await target(service_call)
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/srv/homeassistant/lib/python3.12/site-packages/homeassistant/helpers/service.py", line 977, in entity_service_call
single_response = await _handle_entity_call(
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/srv/homeassistant/lib/python3.12/site-packages/homeassistant/helpers/service.py", line 1049, in _handle_entity_call
result = await task
^^^^^^^^^^
File "/srv/homeassistant/lib/python3.12/site-packages/homeassistant/components/media_player/__init__.py", line 880, in async_select_source
await self.hass.async_add_executor_job(self.select_source, source)
File "/usr/lib/python3.12/concurrent/futures/thread.py", line 58, in run
result = self.fn(*self.args, **self.kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/homeassistant/.homeassistant/custom_components/spotifyplus/media_player.py", line 224, in wrapper
raise HomeAssistantError(ex.Message)
homeassistant.exceptions.HomeAssistantError: SAM0001E - An unhandled exception occured while processing method "PlayerTransferPlayback".
SAM1003E - Spotify ZeroConf API returned an error status while processing the "Connect" method.
Status: 500 - Internal Server Error
Message: "Internal Server Error"

Diagnostics dump

config_entry-hacs-d1b378e2b57174751486942b25aa3676.json

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 73 (29 by maintainers)

Most upvoted comments

Thank you! I’ve never gotten help anywhere near this level with someone working on a codebase. Especially the response time. That made it easy for me so I don’t get distracted by something else shiny. I work with dev teams every day and they pay me to sit and wait most of the time. Good luck!!