-
-
Notifications
You must be signed in to change notification settings - Fork 102
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
homeassistant.exceptions.HomeAssistantError: Could not get spotify token #319
Comments
Hi, Can you help me with this? |
same issue This error originated from a custom integration. Logger: homeassistant Error doing job: Task exception was never retrieved File "/usr/local/lib/python3.9/site-packages/requests/sessions.py", line 542, in get During handling of the above exception, another exception occurred: Traceback (most recent call last): |
Same issue. Tried re-pulling the cookies and updating config but didn't help. |
Update : This may be the cause of the issue? |
Nope, mine says i am on 7.6 |
Not seeing this on my install. Are you all on 2022.4 by any chance? I'm still on 2022.3 |
Yes i am on 2022.4 but had this on 2022.3 aswell. I have updated to 2022.4 before i posted this to see if it would fix my issue. |
I did the same as updating has solved issues in the past. Were you able to solve this? |
Unfortunately, this did not solve my issue. |
The update to HassOS this morning and supervisor fixed it for me. |
looks like a change in spotify token management. I'll look into it. Maybe a change from Spotify API |
After testing I am unable to replicate the issue. At first glance, it would be problem with dependency resolving. Since all people that seem to have the problem run HassOS, it could be a bad config in the update that wiped the dependencies, i.e. Spotify_Token in our case. The problem is that when we try to call spotify_token (the script we use to get the spotify_token) we raise an error if anything fails. To be able to diagnose further I would need more testing data from someone that has the issue and would be willing to test a modified version of Spotcast that deliberately doesn't handle error for that portion. If anyone is confortable to test that simply respond @ing me in the message. |
Hi, any updates? Thanks |
Sure, i can test. |
|
Hi @r11a , @umutcelebi, here is the change to make. I don't want to push an update because reinstalling Spotcast might resolve the issue, but I want to make sure we can get to the root of the problem first. You would need to modify the The change to make is from line 150 to 152: except Exception as e: # noqa: E722
_LOGGER.error(e)
raise HomeAssistantError("Could not get spotify token") Basically:
This should give us more details on what is going on |
this is what I'm getting: This error originated from a custom integration. Logger: custom_components.spotcast.spotcast_controller Exceeded 30 redirects. |
@r11a ok thank you, so there seems to be a problem with how your Spotify app integration is setup. Spotcast is trying to acquire a token from the Spotify integration but is getting in a redirect loop.
|
@fcusson Thank you for your help :)
|
Logger: custom_components.spotcast.spotcast_controller Exceeded 30 redirects. Logger: homeassistant.components.websocket_api.http.connection [140291256728736] Could not get spotify token During handling of the above exception, another exception occurred: Traceback (most recent call last): Is your Spotify integration working correctly? Via the media browser this does not work either. Same error. |
I have (had) the same issue. I did some testing by cloning the "spotify_token" package and adding some additional debugging to the requests. See attached debug.log, it seems the requests gets a 302 response pointing to the same url, most relevant bit below:
I then tried to use new values for sp_dc and sp_key, and got a 200. I then tried updating my sp_dc and sp_key in HA and restarted, and now it seems to work. I think the issue for me at least must have been expired values for sp_dc and sp_key (if the expiration is one year, that might fit well for me). I saw someone else did not fix this by getting new values, but perhaps try again just to be absolutely certain it might not be the same problem? Also, if so - perhaps an error of "too many redirects" could be caught and push a more detailed error to HA, e.g. "Could not get spotify token - might be expired values for sp_dc and sp_key, try getting new values"? |
Wow thank you @Gramatus I was still debugging from our end at this point. We could filter the error type and send a more specific message based on that. I'll work on PR for that. In the meantime, @r11a @umutcelebi, can you confirm updating your sp_dc and sp_key resolves the issue? |
@fcusson unfraternally no :( attached new log file after spotcast reinstall and new sp_dc and sp_key This error originated from a custom integration. Logger: homeassistant Error doing job: Task exception was never retrieved During handling of the above exception, another exception occurred: Traceback (most recent call last): |
@fcusson I have tried to get new sp_dc and sp_key again and now it works :) |
Yes, i can confirm this is working. I have checked the new sp_dc and sp_key via the settings and pasted the new values. After restarting the instance all is working fine. Thanks! |
with the information we have I made a change to the get_spotify_token method: def get_spotify_token(self) -> tuple[str, int]:
try:
self._access_token, self._token_expires = st.start_session(
self.sp_dc, self.sp_key
)
expires = self._token_expires - int(time.time())
return self._access_token, expires
except TooManyRedirects:
_LOGGER.error("Could not get spotify token. sp_dc and sp_key could be expired. Please update in config.")
raise HomeAssistantError("Expired sp_dc, sp_key")
except: # noqa: E722
raise HomeAssistantError("Could not get spotify token.") Now the error message will clearly point toward an expired token for this particular behavior. |
@fcusson @hmmbob @Gramatus @umutcelebi Thank you very much! |
Deze fout is ontstaan door een aangepaste integratie.
Logger: homeassistant
Source: custom_components/spotcast/spotcast_controller.py:151
Integration: Spotcast (documentation, issues)
First occurred: 18:09:37 (1 occurrences)
Last logged: 18:09:37
Error doing job: Task exception was never retrieved
Traceback (most recent call last):
File "/config/custom_components/spotcast/spotcast_controller.py", line 145, in get_spotify_token
self._access_token, self._token_expires = st.start_session(
File "/usr/local/lib/python3.9/site-packages/spotify_token.py", line 18, in start_session
response = session.get("https://open.spotify.com/get_access_token?reason=transport&productType=web_player",
File "/usr/local/lib/python3.9/site-packages/requests/sessions.py", line 542, in get
return self.request('GET', url, **kwargs)
File "/usr/local/lib/python3.9/site-packages/requests/sessions.py", line 529, in request
resp = self.send(prep, **send_kwargs)
File "/usr/local/lib/python3.9/site-packages/requests/sessions.py", line 667, in send
history = [resp for resp in gen]
File "/usr/local/lib/python3.9/site-packages/requests/sessions.py", line 667, in
history = [resp for resp in gen]
File "/usr/local/lib/python3.9/site-packages/requests/sessions.py", line 166, in resolve_redirects
raise TooManyRedirects('Exceeded {} redirects.'.format(self.max_redirects), response=resp)
requests.exceptions.TooManyRedirects: Exceeded 30 redirects.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/config/custom_components/spotcast/helpers.py", line 91, in run
return await loop.run_in_executor(executor, pfunc)
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 98, in get_devices
client = spotcast_controller.get_spotify_client(account)
File "/config/custom_components/spotcast/spotcast_controller.py", line 179, in get_spotify_client
return spotipy.Spotify(auth=self.get_token_instance(account).access_token)
File "/config/custom_components/spotcast/spotcast_controller.py", line 139, in access_token
self.ensure_token_valid()
File "/config/custom_components/spotcast/spotcast_controller.py", line 135, in ensure_token_valid
self.get_spotify_token()
File "/config/custom_components/spotcast/spotcast_controller.py", line 151, in get_spotify_token
raise HomeAssistantError("Could not get spotify token")
homeassistant.exceptions.HomeAssistantError: Could not get spotify token
The text was updated successfully, but these errors were encountered: