spotcast: spotipy.exceptions.SpotifyException: http status: 404, code:-1 - https://api.spotify.com/v1/me/player: Device not found, reason: None
Bug Ticket
Describe the bug
I am using Spotify Premium and i am trying to switch playback from my Macbook desktop app and my Amazon Echo Show. The switch works perfectly FROM my Amazon Echo Show (Mikaels Echo Küche) to my Macbook. Unfortunately, the switch doesn’t work the other way around and I’m getting the following message:
spotipy.exceptions.SpotifyException: http status: 404, code:-1 - https://api.spotify.com/v1/me/player:
Device not found, reason: None
I have regenerated the Client ID / Secret.
Troubleshooting
Make sure to validate all the elements before submitting the ticket (Exception to the steps marked as optional)
- Using latest version of spotcast
- Using latest stable version of Home Assistant
- I have setup the Spotify integration in Home Assistant
- [] I have renewed my
sp_dcandsp_keyvalues and restarted Home Assistant (see README) - (optional) I have Spotify Premium
- (optional) I am using multiple accounts
- (optional) I’m attaching relevant logs with level debug for component spotcast (see README)
- (optional) I’m using entity_id in the service call and have tried device_name but the issue remains
Environment
- Installation type: [Supervised]
- HA version: [ Home Assistant 2023.2.5]
- spotcast version: [3.7.0 ]
Configuration
My device ID fetched via https://developer.spotify.com/console/get-users-available-devices/
{
"id": "b694c2fe-b102-46f6-b4b1-903f7cbcff5c_amzn_1",
"is_active": false,
"is_private_session": false,
"is_restricted": false,
"name": "Mikaels Echo Küche",
"type": "Speaker",
"volume_percent": 45
},
Service Call
If relevant, provide a yaml of the service call or explain the action taken to replicate the issue.
service: spotcast.start
data:
device_name: "Mikaels Echo Küche"
spotify_device_id: b694c2fe-b102-46f6-b4b1-903f7cbcff5c_amzn_1
entity_id: media_player.spotify_hell255
force_playback: true
Logs
- normal
Logger: homeassistant.components.websocket_api.http.connection
Source: custom_components/spotcast/__init__.py:232
Integration: Home Assistant WebSocket API ([documentation](https://www.home-assistant.io/integrations/websocket_api), [issues](https://github.com/home-assistant/home-assistant/issues?q=is%3Aissue+is%3Aopen+label%3A%22integration%3A+websocket_api%22))
First occurred: 15:48:23 (9 occurrences)
Last logged: 17:02:32
[140221505362992] Error handling message: Unknown error (unknown_error) from 192.168.1.77 (Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:109.0) Gecko/20100101 Firefox/109.0)
[140221498350688] Error handling message: Unknown error (unknown_error) from 192.168.1.77 (Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:109.0) Gecko/20100101 Firefox/109.0)
[140221916109728] Error handling message: Unknown error (unknown_error) from 192.168.1.77 (Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:109.0) Gecko/20100101 Firefox/109.0)
[140221497674144] Error handling message: Unknown error (unknown_error) from 192.168.1.77 (Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:109.0) Gecko/20100101 Firefox/109.0)
Traceback (most recent call last):
File "/usr/local/lib/python3.10/site-packages/spotipy/client.py", line 269, in _internal_call
response.raise_for_status()
File "/usr/local/lib/python3.10/site-packages/requests/models.py", line 1021, in raise_for_status
raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 404 Client Error: Not Found for url: https://api.spotify.com/v1/me/player
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/components/websocket_api/decorators.py", line 27, in _handle_async_response
await func(hass, connection, msg)
File "/usr/src/homeassistant/homeassistant/components/websocket_api/commands.py", line 646, in handle_execute_script
await script_obj.async_run(msg.get("variables"), context=context)
File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 1524, in async_run
await asyncio.shield(run.async_run())
File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 409, in async_run
await self._async_step(log_exceptions=False)
File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 453, in _async_step
self._handle_exception(
File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 476, in _handle_exception
raise exception
File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 451, in _async_step
await getattr(self, handler)()
File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 684, in _async_call_service_step
await service_task
File "/usr/src/homeassistant/homeassistant/core.py", line 1787, in async_call
task.result()
File "/usr/src/homeassistant/homeassistant/core.py", line 1830, in _execute_service
await self._hass.async_add_executor_job(
File "/usr/local/lib/python3.10/concurrent/futures/thread.py", line 58, in run
result = self.fn(*self.args, **self.kwargs)
File "/config/custom_components/spotcast/__init__.py", line 232, in start_casting
client.transfer_playback(
File "/usr/local/lib/python3.10/site-packages/spotipy/client.py", line 1778, in transfer_playback
return self._put("me/player", payload=data)
File "/usr/local/lib/python3.10/site-packages/spotipy/client.py", line 336, in _put
return self._internal_call("PUT", url, payload, kwargs)
File "/usr/local/lib/python3.10/site-packages/spotipy/client.py", line 291, in _internal_call
raise SpotifyException(
spotipy.exceptions.SpotifyException: http status: 404, code:-1 - https://api.spotify.com/v1/me/player:
Device not found, reason: None
Additional context
<Add any other context about the problem here.>About this issue
- Original URL
- State: closed
- Created a year ago
- Reactions: 1
- Comments: 37
I also have the same issue. I’ve managed to work around a bit as it works if you remove the
_amzn_Xpart from the ID sode2bd28a-5959-40ac-b03c-dc500d7368f8_amzn_2becomesde2bd28a-5959-40ac-b03c-dc500d7368f8.While this still won’t fix anything for most folk, it at least points in the direction of the issue.
so… the suffix is retain… I’ll have to dig deeper, but the behavior is very strange
Fixed this way using device id without suffix “_amzn_1”:
This is the only way to workaround unavailable problems, switching echo errors, device not found etc.
Hope you find this helpful! Greetings
alias: Music Test sequence:
EDIT: if spotify is not playing, source selection seems to be necessary before play_media.
This set should work if shopify is “sleeping”. Tested right now!
Ah yes, I also have the same issue where a speaker and speaker group have the same ID without the
amznprefix. Unfortunately I don’t see a workaround for that right now.Amazing @dazjones , this worked for me too!
Changed from
e3938dc8-6c95-4c24-9e42-af984deb9494_amzn_1to