Teekeks / pyTwitchAPI

A Python 3.7 compatible implementation of the Twitch API, EventSub, PubSub and Chat
https://pytwitchapi.dev
MIT License
254 stars 38 forks source link

KeyError: 'ratelimit-remaining' not found #237

Closed TwoWheelDev closed 1 year ago

TwoWheelDev commented 1 year ago

Noticed the twitch integrationon HomeAssistant wasn't working. Looking at the logs it seems the errors is coming from this library.

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 554, in async_update_ha_state
    await self.async_device_update()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 781, in async_device_update
    await hass.async_add_executor_job(self.update)
  File "/usr/local/lib/python3.10/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/src/homeassistant/homeassistant/components/twitch/sensor.py", line 111, in update
    followers = self._client.get_users_follows(to_id=self.unique_id)["total"]
  File "/usr/local/lib/python3.10/site-packages/twitchAPI/twitch.py", line 1580, in get_users_follows
    result = self.__api_get_request(url, AuthType.EITHER, [])
  File "/usr/local/lib/python3.10/site-packages/twitchAPI/twitch.py", line 391, in __api_get_request
    return self.__check_request_return(req,
  File "/usr/local/lib/python3.10/site-packages/twitchAPI/twitch.py", line 287, in __check_request_return
    if str(response.headers['Ratelimit-Remaining']) == '0' or response.status_code == 429:
  File "/usr/local/lib/python3.10/site-packages/requests/structures.py", line 52, in __getitem__
    return self._store[key.lower()][1]
KeyError: 'ratelimit-remaining'
Teekeks commented 1 year ago

Actually, looks like you use a outdated version of HomeAssistant. until just 3 weeks ago, HA used a wildly outdated version of this library and that bug was fixed over 1 year ago & is fixed in the current version HA now uses. Please update and test again.

TwoWheelDev commented 1 year ago

Ahhh, apologies that has indeed fixed it!

Sorry for the noise!