dylandoamaral / trakt-integration

A Trakt integration for Home Assistant compatible with upcoming media card
MIT License
30 stars 12 forks source link

Integration Setup wont Complete #54

Closed tacogy3 closed 1 year ago

tacogy3 commented 1 year ago

I'm newer to this so please bare with me. I was able to follow everything in the setup guide but on the Intergration page, I see the following error. It keeps trying but never loads. This also prevents me from displaying anything on the Dashboard.

Retrying setup: 0, message='Attempt to decode JSON with unexpected mimetype: ', url=URL('https://api.trakt.tv/shows/140/progress/watched')

engeld commented 1 year ago

I do have the similar (same?) issue that apparently the Trakt API returns some unexpected mimetype:

image
engeld commented 1 year ago

I also investigated the log when home assistant starts up and loads the trakt integration and this is the output:

2022-11-12 23:09:15.027 WARNING (MainThread) [homeassistant.config_entries] Config entry 'Trakt (configuration.yml)' for trakt_tv integration not ready yet: 0, message='Attempt to decode JSON with unexpected mimetype: ', url=URL('https://api.trakt.tv/shows/156417/seasons/1/episodes/2?extended=full'); Retrying in background
2022-11-12 23:09:23.154 ERROR (MainThread) [custom_components.trakt_tv] Unexpected error fetching trakt data: Can't deserialize the following json:
AUTHED_API_GET_LIMIT rate limit exceeded. Please wait 47 seconds then retry your request.
Traceback (most recent call last):
  File "/home/homeassistant/.homeassistant/custom_components/trakt_tv/utils.py", line 55, in deserialize_json
    return json.loads(document)
  File "/usr/lib/python3.9/json/__init__.py", line 346, in loads
    return _default_decoder.decode(s)
  File "/usr/lib/python3.9/json/decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/usr/lib/python3.9/json/decoder.py", line 355, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/srv/homeassistant/lib/python3.9/site-packages/homeassistant/helpers/update_coordinator.py", line 205, in _async_refresh
    self.data = await self._async_update_data()
  File "/srv/homeassistant/lib/python3.9/site-packages/homeassistant/helpers/update_coordinator.py", line 164, in _async_update_data
    return await self.update_method()
  File "/home/homeassistant/.homeassistant/custom_components/trakt_tv/apis/trakt.py", line 284, in retrieve_data
    data = await gather(
  File "/home/homeassistant/.homeassistant/custom_components/trakt_tv/apis/trakt.py", line 268, in fetch_recommendations
    raw_medias = deserialize_json(payload)
  File "/home/homeassistant/.homeassistant/custom_components/trakt_tv/utils.py", line 57, in deserialize_json
    raise TraktException(f"Can't deserialize the following json:\n{document}")
custom_components.trakt_tv.exception.TraktException: Can't deserialize the following json:
AUTHED_API_GET_LIMIT rate limit exceeded. Please wait 47 seconds then retry your request.

It reads like we hit the Trakt API limit and it seems like the Trakt Integration (or the library behind it?) can't handle this case.

dylandoamaral commented 1 year ago

There is no library behind so it is our fault, I will try to fix it using a retry strategy ! Thanks for the investigation.