Taxel / PlexTraktSync

A python script that syncs the movies, shows and ratings between trakt and Plex (without needing a PlexPass or Trakt VIP subscription)
MIT License
1.63k stars 106 forks source link

Crashing randomly : JSONDecodeError from Trakt #975

Closed Spencer-0003 closed 2 years ago

Spencer-0003 commented 2 years ago

Confirmation

The problem

My container crashes every 30 seconds to a minute.

Error trace / logs

Traceback (most recent call last):
  File "/usr/local/lib/python3.10/runpy.py", line 196, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/usr/local/lib/python3.10/runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "/app/plextraktsync/__main__.py", line 18, in <module>
    cli()
  File "/usr/local/lib/python3.10/site-packages/click/core.py", line 1130, in __call__
    return self.main(*args, **kwargs)
  File "/usr/local/lib/python3.10/site-packages/click/core.py", line 1055, in main
    rv = self.invoke(ctx)
  File "/usr/local/lib/python3.10/site-packages/click/core.py", line 1635, in invoke
    rv = super().invoke(ctx)
  File "/usr/local/lib/python3.10/site-packages/click/core.py", line 1404, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/local/lib/python3.10/site-packages/click/core.py", line 760, in invoke
    return __callback(*args, **kwargs)
  File "/usr/local/lib/python3.10/site-packages/click/decorators.py", line 26, in new_func
    return f(get_current_context(), *args, **kwargs)
  File "/app/plextraktsync/cli.py", line 46, in cli
    sync()
  File "/usr/local/lib/python3.10/site-packages/click/core.py", line 1130, in __call__
    return self.main(*args, **kwargs)
  File "/usr/local/lib/python3.10/site-packages/click/core.py", line 1055, in main
    rv = self.invoke(ctx)
  File "/usr/local/lib/python3.10/site-packages/click/core.py", line 1404, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/local/lib/python3.10/site-packages/click/core.py", line 760, in invoke
    return __callback(*args, **kwargs)
  File "/app/plextraktsync/cli.py", line 28, in wrap
    cmd(*args, **kwargs)
  File "/app/plextraktsync/commands/sync.py", line 60, in sync
    runner.sync(walker=w, dry_run=config.dry_run)
  File "/app/plextraktsync/sync.py", line 82, in sync
    walker.trakt.batch.flush(force=True)
  File "/app/plextraktsync/trakt_api.py", line 371, in flush
    self.submit_collection()
  File "/app/plextraktsync/decorators/nocache.py", line 12, in inner
    return method(*args, **kwargs)
  File "/app/plextraktsync/decorators/rate_limit.py", line 22, in wrapper
    return fn(*args, **kwargs)
  File "/app/plextraktsync/decorators/time_limit.py", line 18, in wrapper
    return fn(*args, **kwargs)
  File "/app/plextraktsync/decorators/retry.py", line 25, in wrapper
    return fn(*args, **kwargs)
  File "/app/plextraktsync/trakt_api.py", line 348, in submit_collection
    result = self.trakt_sync_collection(self.collection)
  File "/app/plextraktsync/trakt_api.py", line 385, in trakt_sync_collection
    return trakt.sync.add_to_collection(media_object)
  File "/usr/local/lib/python3.10/site-packages/trakt/core.py", line 587, in inner
    json_data = self._handle_request('post', url, data=args)
  File "/usr/local/lib/python3.10/site-packages/trakt/core.py", line 532, in _handle_request
    json_data = json.loads(response.content.decode('UTF-8', 'ignore'))
  File "/usr/local/lib/python3.10/json/__init__.py", line 346, in loads
    return _default_decoder.decode(s)
  File "/usr/local/lib/python3.10/json/decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/usr/local/lib/python3.10/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)

Expected behavior

Not crash.

Steps to reproduce the behavior

Run the initial setup (enter email and enter the code etc....)

Inspect of problematic items

No response

Workarounds

No response

Install method

docker-compose

Version

0.20.4

Python Version

3.10.5 (main, Jun 7 2022, 19:35:00) [GCC 10.3.1 20211027]

Operating System and Version

Synology DSM 7.1-42661 Update 3

glensc commented 2 years ago

I think trakt api has issues.

The fix is available to have better reporting:

but unfortunately, the maintainer has disappeared:

douginoz commented 2 years ago

I just ran plextraktsync for the first time in months after updating it, and it got through all my libraries except failed at the start of the TV library. Subsequent running continued past this point.

INFO     Marking as watched in Plex: <tmdb:537648:Episode:244129:Adventure-Time-s02e13>                                                                                              
INFO     Adding to collection: <tmdb:537652:Episode:244130:Adventure-Time-s02e14>                                                                                                    
INFO     Marking as watched in Plex: <tmdb:537652:Episode:244130:Adventure-Time-s02e14>                                                                                              
INFO     Adding to collection: <tmdb:537653:Episode:244131:Adventure-Time-s02e15>                                                                                                    
INFO     Adding to collection: <tmdb:537654:Episode:244132:Adventure-Time-s02e16>                                                                                                    
INFO     Adding to collection: <tmdb:537655:Episode:244134:Adventure-Time-s02e17>                                                                                                    
INFO     Adding to collection: <tmdb:537649:Episode:244133:Adventure-Time-s02e18>                                                                                                    
INFO     Adding to collection: <tmdb:537650:Episode:244135:Adventure-Time-s02e19> 
Processing TV Shows   1% ━━━━━━━━━━━━ 13/1,038  [ 0:03:14 < 0:35:32 , 0 it/s ]
Traceback (most recent call last):
  File "/home/moa/.local/bin/plextraktsync", line 8, in <module>
    sys.exit(cli())
  File "/home/moa/.local/pipx/venvs/PlexTraktSync/lib/python3.8/site-packages/click/core.py", line 1130, in __call__
    return self.main(*args, **kwargs)
  File "/home/moa/.local/pipx/venvs/PlexTraktSync/lib/python3.8/site-packages/click/core.py", line 1055, in main
    rv = self.invoke(ctx)
[etc etc - stack same as previously reported, and finishes as below]
 File "/home/moa/.local/pipx/venvs/PlexTraktSync/lib/python3.8/site-packages/plextraktsync/trakt_api.py", line 385, in trakt_sync_collection
    return trakt.sync.add_to_collection(media_object)
  File "/home/moa/.local/pipx/venvs/PlexTraktSync/lib/python3.8/site-packages/trakt/core.py", line 587, in inner
    json_data = self._handle_request('post', url, data=args)
  File "/home/moa/.local/pipx/venvs/PlexTraktSync/lib/python3.8/site-packages/trakt/core.py", line 532, in _handle_request
    json_data = json.loads(response.content.decode('UTF-8', 'ignore'))
  File "/usr/lib/python3.8/json/__init__.py", line 357, in loads
    return _default_decoder.decode(s)
  File "/usr/lib/python3.8/json/decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/usr/lib/python3.8/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)

$ plextraktsync info PlexTraktSync Version: 0.20.4 Python Version: 3.8.10 (default, Jun 22 2022, 20:18:18) [GCC 9.4.0] Plex API Version: 4.11.2 Trakt API Version: 3.4.0 Cache Dir: /home/moa/.cache/PlexTraktSync Config Dir: /home/moa/.config/PlexTraktSync Log Dir: /home/moa/.cache/PlexTraktSync/log Plex username: xxxxx Trakt username: xxx Plex Server version: 1.27.2.5929-a806c5905, updated at: 2022-07-17 22:00:35 Enabled 11 libraries in Plex Server: ['Christmas Movies', 'Christmas TV Shows', 'Concerts', 'Movies', 'Movies - 3D', 'Movies - 4K', 'Opera', 'TV Shows', 'Christmas Music', 'Classical Music', 'Music']

darylf commented 2 years ago

I'm seeing the JSONDecodeError as well, and it seems to be while adding the same TV episode to collection every time.

INFO Adding to collection: <tmdb:941535:Episode:11744:Doctor-Who-(2005)-s06e05>

Here's the stack trace:

Traceback (most recent call last):
  File "/home/username/.local/bin/plextraktsync", line 8, in <module>
    sys.exit(cli())
  File "/home/username/.local/pipx/venvs/plextraktsync/lib/python3.10/site-packages/click/core.py", line 1130, in __call__
    return self.main(*args, **kwargs)
  File "/home/username/.local/pipx/venvs/plextraktsync/lib/python3.10/site-packages/click/core.py", line 1055, in main
    rv = self.invoke(ctx)
  File "/home/username/.local/pipx/venvs/plextraktsync/lib/python3.10/site-packages/click/core.py", line 1635, in invoke
    rv = super().invoke(ctx)
  File "/home/username/.local/pipx/venvs/plextraktsync/lib/python3.10/site-packages/click/core.py", line 1404, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/home/username/.local/pipx/venvs/plextraktsync/lib/python3.10/site-packages/click/core.py", line 760, in invoke
    return __callback(*args, **kwargs)
  File "/home/username/.local/pipx/venvs/plextraktsync/lib/python3.10/site-packages/click/decorators.py", line 26, in new_func
    return f(get_current_context(), *args, **kwargs)
  File "/home/username/.local/pipx/venvs/plextraktsync/lib/python3.10/site-packages/plextraktsync/cli.py", line 46, in cli
    sync()
  File "/home/username/.local/pipx/venvs/plextraktsync/lib/python3.10/site-packages/click/core.py", line 1130, in __call__
    return self.main(*args, **kwargs)
  File "/home/username/.local/pipx/venvs/plextraktsync/lib/python3.10/site-packages/click/core.py", line 1055, in main
    rv = self.invoke(ctx)
  File "/home/username/.local/pipx/venvs/plextraktsync/lib/python3.10/site-packages/click/core.py", line 1404, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/home/username/.local/pipx/venvs/plextraktsync/lib/python3.10/site-packages/click/core.py", line 760, in invoke
    return __callback(*args, **kwargs)
  File "/home/username/.local/pipx/venvs/plextraktsync/lib/python3.10/site-packages/plextraktsync/cli.py", line 28, in wrap
    cmd(*args, **kwargs)
  File "/home/username/.local/pipx/venvs/plextraktsync/lib/python3.10/site-packages/plextraktsync/commands/sync.py", line 60, in sync
    runner.sync(walker=w, dry_run=config.dry_run)
  File "/home/username/.local/pipx/venvs/plextraktsync/lib/python3.10/site-packages/plextraktsync/sync.py", line 75, in sync
    self.sync_collection(episode, dry_run=dry_run)
  File "/home/username/.local/pipx/venvs/plextraktsync/lib/python3.10/site-packages/plextraktsync/sync.py", line 103, in sync_collection
    m.add_to_collection(batch=True)
  File "/home/username/.local/pipx/venvs/plextraktsync/lib/python3.10/site-packages/plextraktsync/media.py", line 90, in add_to_collection
    self.trakt_api.add_to_collection(self.trakt, self.plex, batch=batch)
  File "/home/username/.local/pipx/venvs/plextraktsync/lib/python3.10/site-packages/plextraktsync/trakt_api.py", line 235, in add_to_collection
    self.batch.add_to_collection(m.media_type, item)
  File "/home/username/.local/pipx/venvs/plextraktsync/lib/python3.10/site-packages/plextraktsync/trakt_api.py", line 381, in add_to_collection
    self.flush()
  File "/home/username/.local/pipx/venvs/plextraktsync/lib/python3.10/site-packages/plextraktsync/trakt_api.py", line 371, in flush
    self.submit_collection()
  File "/home/username/.local/pipx/venvs/plextraktsync/lib/python3.10/site-packages/plextraktsync/decorators/nocache.py", line 12, in inner
    return method(*args, **kwargs)
  File "/home/username/.local/pipx/venvs/plextraktsync/lib/python3.10/site-packages/plextraktsync/decorators/rate_limit.py", line 22, in wrapper
    return fn(*args, **kwargs)
  File "/home/username/.local/pipx/venvs/plextraktsync/lib/python3.10/site-packages/plextraktsync/decorators/time_limit.py", line 18, in wrapper
    return fn(*args, **kwargs)
  File "/home/username/.local/pipx/venvs/plextraktsync/lib/python3.10/site-packages/plextraktsync/decorators/retry.py", line 25, in wrapper
    return fn(*args, **kwargs)
  File "/home/username/.local/pipx/venvs/plextraktsync/lib/python3.10/site-packages/plextraktsync/trakt_api.py", line 348, in submit_collection
    result = self.trakt_sync_collection(self.collection)
  File "/home/username/.local/pipx/venvs/plextraktsync/lib/python3.10/site-packages/plextraktsync/trakt_api.py", line 385, in trakt_sync_collection
    return trakt.sync.add_to_collection(media_object)
  File "/home/username/.local/pipx/venvs/plextraktsync/lib/python3.10/site-packages/trakt/core.py", line 587, in inner
    json_data = self._handle_request('post', url, data=args)
  File "/home/username/.local/pipx/venvs/plextraktsync/lib/python3.10/site-packages/trakt/core.py", line 532, in _handle_request
    json_data = json.loads(response.content.decode('UTF-8', 'ignore'))
  File "/usr/lib/python3.10/json/__init__.py", line 346, in loads
    return _default_decoder.decode(s)
  File "/usr/lib/python3.10/json/decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/usr/lib/python3.10/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)

I'm not sure if there's an additional log I could provide with more info.

glensc commented 2 years ago

JSONDecodeError probably means trakt.tv site errors. should be recovered with a retry at some point.

darylf commented 2 years ago

Is there any way for the app to eat the error and continue? Or perhaps meet a certain number of errors before it fails?

glensc commented 2 years ago

it's there waiting for PyTrakt change: