haijeploeg / excludarr

Excludarr manages your libraries in Radarr/Sonarr. It keeps track of your library and checks if your movies and series are also available on a configured streaming provider. It can exclude the movies and series that are available on a configured streaming provider. But it can also re-add movies and series if they are not streaming anymore.
MIT License
197 stars 12 forks source link

Version 1.0.1 sonarr exclude JSONDecodeError sometimes #26

Closed haijeploeg closed 2 years ago

haijeploeg commented 2 years ago

When executing excludarr sonarr exclude I sometimes get a traceback about a JSONDecodeError:

Traceback (most recent call last):
  File "/usr/local/bin/excludarr", line 8, in <module>
    sys.exit(cli())
  File "/usr/local/lib/python3.8/dist-packages/excludarr/main.py", line 68, in cli
    app(prog_name="excludarr")
  File "/usr/local/lib/python3.8/dist-packages/typer/main.py", line 214, in __call__
    return get_command(self)(*args, **kwargs)
  File "/usr/local/lib/python3.8/dist-packages/click/core.py", line 1128, in __call__
    return self.main(*args, **kwargs)
  File "/usr/local/lib/python3.8/dist-packages/click/core.py", line 1053, in main
    rv = self.invoke(ctx)
  File "/usr/local/lib/python3.8/dist-packages/click/core.py", line 1659, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/usr/local/lib/python3.8/dist-packages/click/core.py", line 1659, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/usr/local/lib/python3.8/dist-packages/click/core.py", line 1395, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/local/lib/python3.8/dist-packages/click/core.py", line 754, in invoke
    return __callback(*args, **kwargs)
  File "/usr/local/lib/python3.8/dist-packages/typer/main.py", line 500, in wrapper
    return callback(**use_params)  # type: ignore
  File "/usr/local/lib/python3.8/dist-packages/excludarr/commands/sonarr.py", line 69, in exclude
    series_to_exclude = sonarr.get_series_to_exclude(
  File "/usr/local/lib/python3.8/dist-packages/excludarr/core/sonarr_actions.py", line 158, in get_series_to_exclude
    sonarr_series = self.sonarr_client.serie.get_all_series()
  File "/usr/local/lib/python3.8/dist-packages/excludarr/modules/pysonarr/v3/serie.py", line 13, in get_all_series
    return self.client.http_get(self.serie_path)
  File "/usr/local/lib/python3.8/dist-packages/excludarr/modules/pysonarr/__init__.py", line 70, in http_get
    return self.http_request("get", path, params=params)
  File "/usr/local/lib/python3.8/dist-packages/excludarr/modules/pysonarr/__init__.py", line 67, in http_request
    return self._filter_api_error(result)
  File "/usr/local/lib/python3.8/dist-packages/excludarr/modules/pysonarr/__init__.py", line 54, in _filter_api_error
    result_json = data.json()
  File "/usr/local/lib/python3.8/dist-packages/requests/models.py", line 910, in json
    return complexjson.loads(self.text, **kwargs)
  File "/usr/lib/python3/dist-packages/simplejson/__init__.py", line 518, in loads
    return _default_decoder.decode(s)
  File "/usr/lib/python3/dist-packages/simplejson/decoder.py", line 370, in decode
    obj, end = self.raw_decode(s)
  File "/usr/lib/python3/dist-packages/simplejson/decoder.py", line 400, in raw_decode
    return self.scan_once(s, idx=_w(s, idx).end())
simplejson.errors.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

Simply retrying will fix the issue. This can happen if the API of Sonarr is not reporting the correct information. A possible solution is to just retrying the API call for max 3 times for example.