"Error", aiohttp.client_exceptions.ClientResponseError: 400, message='Bad Request', spotify integration

1- Removed spotify integrations details from config.yaml
2- restarted HA
3- go to integrations page to add spotify integration, fails with the following error

4- The fix in this post was to add both URLs to my applications "Redirect URI”,
Applications Dashboard

http://homeassistant.local:8123/auth/external/callback
https://my.home-assistant.io/redirect/oauth/

5- go to integrations page AGAIN to add spotify integration,
this time I do finanlly get to the redirect page

the link account references my local instance url.

Your instance URL: https://homeassistant.local:8123

However once I click on Link Account, I encounter an “error”

Screen Shot 2022-08-19 at 7.53.58 AM

of course going deeper into the logs, I find the following

Traceback (most recent call last):
  File "/usr/local/lib/python3.10/site-packages/aiohttp/web_protocol.py", line 435, in _handle_request
    resp = await request_handler(request)
  File "/usr/local/lib/python3.10/site-packages/aiohttp/web_app.py", line 504, in _handle
    resp = await handler(request)
  File "/usr/local/lib/python3.10/site-packages/aiohttp/web_middlewares.py", line 117, in impl
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/security_filter.py", line 60, in security_filter_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/forwarded.py", line 222, in forwarded_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/request_context.py", line 28, in request_context_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/ban.py", line 82, in ban_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/auth.py", line 236, in auth_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/view.py", line 136, in handle
    result = await result
  File "/usr/src/homeassistant/homeassistant/components/config/config_entries.py", line 168, in get
    return await super().get(request, flow_id)
  File "/usr/src/homeassistant/homeassistant/helpers/data_entry_flow.py", line 95, in get
    result = await self._flow_mgr.async_configure(flow_id)
  File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 277, in async_configure
    result = await self._async_handle_step(
  File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 359, in _async_handle_step
    result: FlowResult = await getattr(flow, method)(user_input)
  File "/usr/src/homeassistant/homeassistant/helpers/config_entry_oauth2_flow.py", line 303, in async_step_creation
    token = await self.flow_impl.async_resolve_external_data(self.external_data)
  File "/usr/src/homeassistant/homeassistant/helpers/config_entry_oauth2_flow.py", line 169, in async_resolve_external_data
    return await self._token_request(
  File "/usr/src/homeassistant/homeassistant/helpers/config_entry_oauth2_flow.py", line 205, in _token_request
    resp.raise_for_status()
  File "/usr/local/lib/python3.10/site-packages/aiohttp/client_reqrep.py", line 1004, in raise_for_status
    raise ClientResponseError(
aiohttp.client_exceptions.ClientResponseError: 400, message='Bad Request', url=URL('https://accounts.spotify.com/api/token')

the last line of the error refers to a github issue from 2022.6.

2 things I learned…

first application credentials were cached from what was previously in the config files, so removing the spotify credentials here is important.

second you need the my home assistant to point to your https://homeassistant.local:8123

in the end, worked, as is, no need for a second redirect link, as well as you get asked to enter your oauth client id and key if they’re not stored in your “Applications Credentials”

i wonder how many people knew this very thing, understand it’s not documented anywhere and just strolled along when they saw this post?

1 Like