Closed jonnybergdahl closed 6 months ago
Some more details, since this stops working after some time I would expect authentication to be the main issue.
HA is handling the OAuth handshake itself, since it needs to keep track of the current token, so using client.auto_refresh_auth = False
.
Problem is that the call doesn't fail, but just return without the total
field present. I would have expected some kind of authentication error exception.
hm that should still raise an exception, thanks for the further investigation!
It gets more strange. I changed the code to actually refresh the token when it expired and I still get the same error. I get this at startup.
2024-03-09 00:23:40.582 DEBUG (MainThread) [homeassistant.components.twitch.sensor] Token: {'access_token': 'whr8pbvgcy61jupn0harp5aqd02eh3', 'expires_in': 15759, 'refresh_token': 'f56blnott4u856pwlay1sxrvxbsdlu9vg5v7mn4olhf0cnkz0d', 'scope': ['user:read:follows', 'user:read:subscriptions'], 'token_type': 'bearer', 'expires_at': 1709954343.5376744}
Couple of hours later the log shows the above problem, with this auth, so it did indeed do a token refresh.
2024-03-09 00:29:38.069 DEBUG (MainThread) [homeassistant.components.twitch.sensor] Token: {'access_token': 'whr8pbvgcy61jupn0harp5aqd02eh3', 'expires_in': 15759, 'refresh_token': 'f56blnott4u856pwlay1sxrvxbsdlu9vg5v7mn4olhf0cnkz0d', 'scope': ['user:read:follows', 'user:read:subscriptions'], 'token_type': 'bearer', 'expires_at': 1709954343.5376744}
The log is complaining about that total
error at that stage again.
I restarted Home Assistant, and the error went away. With the exact same token I used before the restart!?!?!
So not sure it even IS related to auth?
Meanwhile I have fixed the bug in Home Assistant that exposed the problem. It was indeed a token refresh bug.
ae975e3725101f50cd72cfa0e61dd393f1576ff9 should fix this issue by correctly raising a UnauthorizedException even if auto_refresh_auth is set to false
That certainly looks good to me.
Home Assistant is using pyTwitchAPI for the core integration, but it has been broken for a while. I tracked it down to the call to
get_channel_followers
stops returning thetotal
field after a while.I added a simple
ppprint
call, and this is returned at startup.