Invalid context uri
See original GitHub issueBug Ticket
Describe the bug
When calling the service spotcast.start
, It always errors with Invalid context uri
(see more detailed logs below).
This used to work, but broke recently.
- Using latest version of spotcast
- I have setup the Spotify integration in Home Assistant
- I am using multiple accounts
- Using latest stable version of Home Assistant
- I have Spotify Premium
- I’m attaching relevant logs with level debug for component spotcast (see README)
- I’m using entity_id in the service call and have tried device_name but the issue remains
Environment
- Installation type: [Container]
- HA version: [2022.3.4]
- spotcast version: [v3.6.27]
Configuration
spotify:
client_id: **********
client_secret: **********
spotcast:
sp_dc: "**********"
sp_key: "**********"
country: US
sensor:
- platform: spotcast
country: US
Service Call
service: spotcast.start
data:
shuffle: true
uri: Spotify:playlist:4T0R5nCnC3m6yZZWQ045pt
entity_id: media_player.everywhere
Additional context
Errors in logs:
2022-03-14 15:08:20 ERROR (SyncWorker_13) [spotipy.client] HTTP Error for PUT to https://api.spotify.com/v1/me/player/play?device_id=8ed23e57572077f6f5c112b63c0b6279 with Params: {} returned 400 due to Invalid context uri
2022-03-14 15:08:20 ERROR (MainThread) [homeassistant.helpers.script.websocket_api_script] websocket_api script: Error executing script. Unexpected error for call_service at pos 1: http status: 400, code:-1 - https://api.spotify.com/v1/me/player/play?device_id=8ed23e57572077f6f5c112b63c0b6279:
Invalid context uri, reason: None
Traceback (most recent call last):
File "/usr/local/lib/python3.9/site-packages/spotipy/client.py", line 245, in _internal_call
response.raise_for_status()
File "/usr/local/lib/python3.9/site-packages/requests/models.py", line 960, in raise_for_status
raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 400 Client Error: Bad Request for url: https://api.spotify.com/v1/me/player/play?device_id=8ed23e57572077f6f5c112b63c0b6279
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 367, in _async_step
await getattr(self, handler)()
File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 570, in _async_call_service_step
await service_task
File "/usr/src/homeassistant/homeassistant/core.py", line 1636, in async_call
task.result()
File "/usr/src/homeassistant/homeassistant/core.py", line 1679, in _execute_service
await self._hass.async_add_executor_job(
File "/usr/local/lib/python3.9/concurrent/futures/thread.py", line 58, in run
result = self.fn(*self.args, **self.kwargs)
File "/config/custom_components/spotcast/__init__.py", line 217, in start_casting
spotcast_controller.play(
File "/config/custom_components/spotcast/spotcast_controller.py", line 277, in play
client.start_playback(**kwargs)
File "/usr/local/lib/python3.9/site-packages/spotipy/client.py", line 1767, in start_playback
return self._put(
File "/usr/local/lib/python3.9/site-packages/spotipy/client.py", line 312, in _put
return self._internal_call("PUT", url, payload, kwargs)
File "/usr/local/lib/python3.9/site-packages/spotipy/client.py", line 267, in _internal_call
raise SpotifyException(
spotipy.exceptions.SpotifyException: http status: 400, code:-1 - https://api.spotify.com/v1/me/player/play?device_id=8ed23e57572077f6f5c112b63c0b6279:
Invalid context uri, reason: None
2022-03-14 15:08:20 ERROR (MainThread) [homeassistant.components.websocket_api.http.connection] [140145197406288] Error handling message: Unknown error
Traceback (most recent call last):
File "/usr/local/lib/python3.9/site-packages/spotipy/client.py", line 245, in _internal_call
response.raise_for_status()
File "/usr/local/lib/python3.9/site-packages/requests/models.py", line 960, in raise_for_status
raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 400 Client Error: Bad Request for url: https://api.spotify.com/v1/me/player/play?device_id=8ed23e57572077f6f5c112b63c0b6279
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 552, in handle_execute_script
await script_obj.async_run(msg.get("variables"), context=context)
File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 1243, in async_run
await asyncio.shield(run.async_run())
File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 349, in async_run
await self._async_step(log_exceptions=False)
File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 367, in _async_step
await getattr(self, handler)()
File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 570, in _async_call_service_step
await service_task
File "/usr/src/homeassistant/homeassistant/core.py", line 1636, in async_call
task.result()
File "/usr/src/homeassistant/homeassistant/core.py", line 1679, in _execute_service
await self._hass.async_add_executor_job(
File "/usr/local/lib/python3.9/concurrent/futures/thread.py", line 58, in run
result = self.fn(*self.args, **self.kwargs)
File "/config/custom_components/spotcast/__init__.py", line 217, in start_casting
spotcast_controller.play(
File "/config/custom_components/spotcast/spotcast_controller.py", line 277, in play
client.start_playback(**kwargs)
File "/usr/local/lib/python3.9/site-packages/spotipy/client.py", line 1767, in start_playback
return self._put(
File "/usr/local/lib/python3.9/site-packages/spotipy/client.py", line 312, in _put
return self._internal_call("PUT", url, payload, kwargs)
File "/usr/local/lib/python3.9/site-packages/spotipy/client.py", line 267, in _internal_call
raise SpotifyException(
spotipy.exceptions.SpotifyException: http status: 400, code:-1 - https://api.spotify.com/v1/me/player/play?device_id=8ed23e57572077f6f5c112b63c0b6279:
Invalid context uri, reason: None
Issue Analytics
- State:
- Created 2 years ago
- Comments:9 (2 by maintainers)
Top Results From Across the Web
Getting Invalid context uri when calling Spotify API start playback
The valid uri should be e.g. "spotify:playlist:aaclI7AQBATZ5XXJF73BZK".
Read more >Getting invalid context URI when passing variable containing ...
I am reading the ID part of the spotify album URI from an external source and concatenating it to a base URI, doing...
Read more >BMXAA8816E - The URI context login is not supported ... - IBM
Problem. When attempting to login to Maximo anywhere using the /maximo/oslc/login context you will receive the following error in the logs.
Read more >Solved: Spotify URI not valid
Solved: I was trying to upload my playlist onto the playlist exchange but when I copy the playlist URI the error I get...
Read more >Welcome to Spotipy! — spotipy 2.0 documentation
import spotipy from spotipy.oauth2 import SpotifyClientCredentials lz_uri ... you will get a 'Player command failed: Restriction violated' error I therefore ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@OzGav that’s because it’s in the dev version but haven’t been released yet. Due to the low impact of the error and that I don’t have a lot of free time at the moment.
Yeah it is in the error message which was messing me around. This is what you get if you format the uri incorrectly:
is not a valid URI. The format should be [Spotify.<type>.<unique_id>]
So there is two things wrong with that, the leading capital S and the . instead of :edit; Looks like the : has been fixed but not the capital S custom_components/spotcast/helpers.py
edit2: I have raised a PR. Not sure why I am seeing an incorrect error message though with the colon as I only installed this tonight?