Taxel / PlexTraktSync

A python script that syncs the movies, shows and ratings between trakt and Plex (without needing a PlexPass or Trakt VIP subscription)

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Internal server error

pterisaur opened this issue · comments

Confirmation

  • I have read the README.md on the project homepage
  • I have checked if identical issue already exists
  • I have tried downgrading to find version that can be used as a workaround

The problem

When I run plextraktsync sync, I get an internal server error about halfway through my TV Shows library.

Error trace / logs

Processing TV Shows  55% ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╺━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 457/833  [ 0:01:31 < 0:00:47 , 8 it/s ]
[2023-11-16 00:42:37] ERROR    (500) internal_server_error;                                                                                                         
                               https://10-0-1-10.808cbc6741f14352b9c77bd45b676e74.plex.direct:32400/library/metadata/539544/children?excludeAllLeaves=1&index=None  
                               <html><head><title>Internal Server Error</title></head><body><h1>500 Internal Server Error</h1></body></html>                        
                               ╭──────────────────────────────────────────────── Traceback (most recent call last) ────────────────────────────────────────────────╮
                               │ /Users/alpacalypse/.local/pipx/venvs/plextraktsync/lib/python3.10/site-packages/plextraktsync/cli.py:26 in wrap                   │
                               │                                                                                                                                   │
                               │    23 │   │   │   cmd = getattr(module, name)                                                                                     │
                               │    24 │   │   │                                                                                                                   │
                               │    25 │   │   │   try:                                                                                                            │
                               │ ❱  26 │   │   │   │   cmd(*args, **kwargs)                                                                                        │
                               │    27 │   │   │   except ClickException as e:                                                                                     │
                               │    28 │   │   │   │   from plextraktsync.factory import logger                                                                    │
                               │    29 │   │   │   │   logger.fatal(f"Error running {name} command: {str(e)}")                                                     │
                               │                                                                                                                                   │
                               │ /Users/alpacalypse/.local/pipx/venvs/plextraktsync/lib/python3.10/site-packages/plextraktsync/commands/sync.py:68 in sync         │
                               │                                                                                                                                   │
                               │   65 │   │   │   w.print_plan(print=logger.info)                                                                                  │
                               │   66 │   │   if dry_run:                                                                                                          │
                               │   67 │   │   │   logger.info("Enabled dry-run mode: not making actual changes")                                                   │
                               │ ❱ 68 │   │   runner.sync(walker=w, dry_run=config.dry_run)                                                                        │
                               │   69                                                                                                                              │
                               │                                                                                                                                   │
                               │ /Users/alpacalypse/.local/pipx/venvs/plextraktsync/lib/python3.10/site-packages/plextraktsync/sync.py:79 in sync                  │
                               │                                                                                                                                   │
                               │    76 │   │   │                                                                                                                   │
                               │    77 │   │   │   shows = set()                                                                                                   │
                               │    78 │   │   │   episode_trakt_ids = set()                                                                                       │
                               │ ❱  79 │   │   │   for episode in walker.find_episodes():                                                                          │
                               │    80 │   │   │   │   self.sync_collection(episode, dry_run=dry_run)                                                              │
                               │    81 │   │   │   │   self.sync_ratings(episode, dry_run=dry_run)                                                                 │
                               │    82 │   │   │   │   self.sync_watched(episode, dry_run=dry_run)                                                                 │
                               │                                                                                                                                   │
                               │ /Users/alpacalypse/.local/pipx/venvs/plextraktsync/lib/python3.10/site-packages/plextraktsync/walker.py:303 in find_episodes      │
                               │                                                                                                                                   │
                               │   300 │   │   │   show = self.mf.resolve_any(ps)                                                                                  │
                               │   301 │   │   │   if not show:                                                                                                    │
                               │   302 │   │   │   │   continue                                                                                                    │
                               │ ❱ 303 │   │   │   yield from self.episode_from_show(show)                                                                         │
                               │   304 │                                                                                                                           │
                               │   305 │   def walk_shows(self, shows: set[Media], title="Processing Shows"):                                                      │
                               │   306 │   │   if not shows:                                                                                                       │
                               │                                                                                                                                   │
                               │ /Users/alpacalypse/.local/pipx/venvs/plextraktsync/lib/python3.10/site-packages/plextraktsync/walker.py:343 in episode_from_show  │
                               │                                                                                                                                   │
                               │   340 │                                                                                                                           │
                               │   341 │   def episode_from_show(self, show: Media) -> Generator[Media, Any, None]:                                                │
                               │   342 │   │   for pe in show.plex.episodes():                                                                                     │
                               │ ❱ 343 │   │   │   me = self.mf.resolve_any(pe, show)                                                                              │
                               │   344 │   │   │   if not me:                                                                                                      │
                               │   345 │   │   │   │   continue                                                                                                    │
                               │   346                                                                                                                             │
                               │                                                                                                                                   │
                               │ /Users/alpacalypse/.local/pipx/venvs/plextraktsync/lib/python3.10/site-packages/plextraktsync/media.py:252 in resolve_any         │
                               │                                                                                                                                   │
                               │   249 │   │   │   return None                                                                                                     │
                               │   250 │   │                                                                                                                       │
                               │   251 │   │   for guid in guids:                                                                                                  │
                               │ ❱ 252 │   │   │   m = self.resolve_guid(guid, show)                                                                               │
                               │   253 │   │   │   if m:                                                                                                           │
                               │   254 │   │   │   │   return m                                                                                                    │
                               │   255                                                                                                                             │
                               │                                                                                                                                   │
                               │ /Users/alpacalypse/.local/pipx/venvs/plextraktsync/lib/python3.10/site-packages/plextraktsync/media.py:260 in resolve_guid        │
                               │                                                                                                                                   │
                               │   257 │                                                                                                                           │
                               │   258 │   def resolve_guid(self, guid: PlexGuid, show: Media = None):                                                             │
                               │   259 │   │   if guid.provider in ["local", "none", "agents.none"]:                                                               │
                               │ ❱ 260 │   │   │   logger.warning(f"{guid.pm.item}: Skipping {guid} because provider                                               │
                               │       {guid.provider} has no external Id")                                                                                        │
                               │   261 │   │   │                                                                                                                   │
                               │   262 │   │   │   return None                                                                                                     │
                               │   263                                                                                                                             │
                               │                                                                                                                                   │
                               │ /Users/alpacalypse/.local/pipx/venvs/plextraktsync/lib/python3.10/site-packages/plexapi/video.py:975 in __repr__                  │
                               │                                                                                                                                   │
                               │    972 │   │   │   ':'.join([p for p in [                                                                                         │
                               │    973 │   │   │   │   self.__class__.__name__,                                                                                   │
                               │    974 │   │   │   │   self.key.replace('/library/metadata/', '').replace('/children', ''),                                       │
                               │ ❱  975 │   │   │   │   f"{self.grandparentTitle.replace(' ', '-')[:20]}-{self.seasonEpisode}",                                    │
                               │    976 │   │   │   ] if p])                                                                                                       │
                               │    977 │   │   )                                                                                                                  │
                               │    978                                                                                                                            │
                               │                                                                                                                                   │
                               │ /Users/alpacalypse/.local/pipx/venvs/plextraktsync/lib/python3.10/site-packages/plexapi/base.py:516 in __getattribute__           │
                               │                                                                                                                                   │
                               │   513 │                                                                                                                           │
                               │   514 │   def __getattribute__(self, attr):                                                                                       │
                               │   515 │   │   # Dragons inside.. :-/                                                                                              │
                               │ ❱ 516 │   │   value = super(PlexPartialObject, self).__getattribute__(attr)                                                       │
                               │   517 │   │   # Check a few cases where we don't want to reload                                                                   │
                               │   518 │   │   if attr in _DONT_RELOAD_FOR_KEYS: return value                                                                      │
                               │   519 │   │   if attr in USER_DONT_RELOAD_FOR_KEYS: return value                                                                  │
                               │                                                                                                                                   │
                               │ /Users/alpacalypse/.local/pipx/venvs/plextraktsync/lib/python3.10/site-packages/plexapi/video.py:1011 in seasonEpisode            │
                               │                                                                                                                                   │
                               │   1008 │   @property                                                                                                              │
                               │   1009 │   def seasonEpisode(self):                                                                                               │
                               │   1010 │   │   """ Returns the s00e00 string containing the season and episode numbers. """                                       │
                               │ ❱ 1011 │   │   return f's{str(self.seasonNumber).zfill(2)}e{str(self.episodeNumber).zfill(2)}'                                    │
                               │   1012 │                                                                                                                          │
                               │   1013 │   @property                                                                                                              │
                               │   1014 │   def hasCommercialMarker(self):                                                                                         │
                               │                                                                                                                                   │
                               │ /Users/alpacalypse/.local/pipx/venvs/plextraktsync/lib/python3.10/site-packages/plexapi/base.py:516 in __getattribute__           │
                               │                                                                                                                                   │
                               │   513 │                                                                                                                           │
                               │   514 │   def __getattribute__(self, attr):                                                                                       │
                               │   515 │   │   # Dragons inside.. :-/                                                                                              │
                               │ ❱ 516 │   │   value = super(PlexPartialObject, self).__getattribute__(attr)                                                       │
                               │   517 │   │   # Check a few cases where we don't want to reload                                                                   │
                               │   518 │   │   if attr in _DONT_RELOAD_FOR_KEYS: return value                                                                      │
                               │   519 │   │   if attr in USER_DONT_RELOAD_FOR_KEYS: return value                                                                  │
                               │                                                                                                                                   │
                               │ /usr/local/Cellar/python@3.10/3.10.2/Frameworks/Python.framework/Versions/3.10/lib/python3.10/functools.py:981 in __get__         │
                               │                                                                                                                                   │
                               │   978 │   │   │   │   # check if another thread filled cache while we awaited lock                                                │
                               │   979 │   │   │   │   val = cache.get(self.attrname, _NOT_FOUND)                                                                  │
                               │   980 │   │   │   │   if val is _NOT_FOUND:                                                                                       │
                               │ ❱ 981 │   │   │   │   │   val = self.func(instance)                                                                               │
                               │   982 │   │   │   │   │   try:                                                                                                    │
                               │   983 │   │   │   │   │   │   cache[self.attrname] = val                                                                          │
                               │   984 │   │   │   │   │   except TypeError:                                                                                       │
                               │                                                                                                                                   │
                               │ /Users/alpacalypse/.local/pipx/venvs/plextraktsync/lib/python3.10/site-packages/plexapi/video.py:1006 in seasonNumber             │
                               │                                                                                                                                   │
                               │   1003 │   @cached_property                                                                                                       │
                               │   1004 │   def seasonNumber(self):                                                                                                │
                               │   1005 │   │   """ Returns the episode's season number. """                                                                       │
                               │ ❱ 1006 │   │   return self.parentIndex if isinstance(self.parentIndex, int) else                                                  │
                               │        self._season.seasonNumber                                                                                                  │
                               │   1007 │                                                                                                                          │
                               │   1008 │   @property                                                                                                              │
                               │   1009 │   def seasonEpisode(self):                                                                                               │
                               │                                                                                                                                   │
                               │ /Users/alpacalypse/.local/pipx/venvs/plextraktsync/lib/python3.10/site-packages/plexapi/base.py:516 in __getattribute__           │
                               │                                                                                                                                   │
                               │   513 │                                                                                                                           │
                               │   514 │   def __getattribute__(self, attr):                                                                                       │
                               │   515 │   │   # Dragons inside.. :-/                                                                                              │
                               │ ❱ 516 │   │   value = super(PlexPartialObject, self).__getattribute__(attr)                                                       │
                               │   517 │   │   # Check a few cases where we don't want to reload                                                                   │
                               │   518 │   │   if attr in _DONT_RELOAD_FOR_KEYS: return value                                                                      │
                               │   519 │   │   if attr in USER_DONT_RELOAD_FOR_KEYS: return value                                                                  │
                               │                                                                                                                                   │
                               │ /usr/local/Cellar/python@3.10/3.10.2/Frameworks/Python.framework/Versions/3.10/lib/python3.10/functools.py:981 in __get__         │
                               │                                                                                                                                   │
                               │   978 │   │   │   │   # check if another thread filled cache while we awaited lock                                                │
                               │   979 │   │   │   │   val = cache.get(self.attrname, _NOT_FOUND)                                                                  │
                               │   980 │   │   │   │   if val is _NOT_FOUND:                                                                                       │
                               │ ❱ 981 │   │   │   │   │   val = self.func(instance)                                                                               │
                               │   982 │   │   │   │   │   try:                                                                                                    │
                               │   983 │   │   │   │   │   │   cache[self.attrname] = val                                                                          │
                               │   984 │   │   │   │   │   except TypeError:                                                                                       │
                               │                                                                                                                                   │
                               │ /Users/alpacalypse/.local/pipx/venvs/plextraktsync/lib/python3.10/site-packages/plexapi/video.py:966 in _season                   │
                               │                                                                                                                                   │
                               │    963 │   │   """ Returns the :class:`~plexapi.video.Season` object by querying for the show's                                   │
                               │        children. """                                                                                                              │
                               │    964 │   │   if not self.grandparentKey:                                                                                        │
                               │    965 │   │   │   return None                                                                                                    │
                               │ ❱  966 │   │   return self.fetchItem(                                                                                             │
                               │    967 │   │   │                                                                                                                  │
                               │        f'{self.grandparentKey}/children?excludeAllLeaves=1&index={self.parentIndex}'                                              │
                               │    968 │   │   )                                                                                                                  │
                               │    969                                                                                                                            │
                               │                                                                                                                                   │
                               │ /Users/alpacalypse/.local/pipx/venvs/plextraktsync/lib/python3.10/site-packages/plexapi/base.py:307 in fetchItem                  │
                               │                                                                                                                                   │
                               │   304 │   │   │   ekey = f'/library/metadata/{ekey}'                                                                              │
                               │   305 │   │                                                                                                                       │
                               │   306 │   │   try:                                                                                                                │
                               │ ❱ 307 │   │   │   return self.fetchItems(ekey, cls, **kwargs)[0]                                                                  │
                               │   308 │   │   except IndexError:                                                                                                  │
                               │   309 │   │   │   clsname = cls.__name__ if cls else 'None'                                                                       │
                               │   310 │   │   │   raise NotFound(f'Unable to find elem: cls={clsname}, attrs={kwargs}') from                                      │
                               │       None                                                                                                                        │
                               │                                                                                                                                   │
                               │ /Users/alpacalypse/.local/pipx/venvs/plextraktsync/lib/python3.10/site-packages/plexapi/base.py:255 in fetchItems                 │
                               │                                                                                                                                   │
                               │   252 │   │   │   headers['X-Plex-Container-Start'] = str(container_start)                                                        │
                               │   253 │   │   │   headers['X-Plex-Container-Size'] = str(container_size)                                                          │
                               │   254 │   │   │                                                                                                                   │
                               │ ❱ 255 │   │   │   data = self._server.query(ekey, headers=headers)                                                                │
                               │   256 │   │   │   subresults = self.findItems(data, cls, ekey, **kwargs)                                                          │
                               │   257 │   │   │   total_size = utils.cast(int, data.attrib.get('totalSize') or                                                    │
                               │       data.attrib.get('size')) or len(subresults)                                                                                 │
                               │   258                                                                                                                             │
                               │                                                                                                                                   │
                               │ /Users/alpacalypse/.local/pipx/venvs/plextraktsync/lib/python3.10/site-packages/plexapi/server.py:770 in query                    │
                               │                                                                                                                                   │
                               │    767 │   │   │   elif response.status_code == 404:                                                                              │
                               │    768 │   │   │   │   raise NotFound(message)                                                                                    │
                               │    769 │   │   │   else:                                                                                                          │
                               │ ❱  770 │   │   │   │   raise BadRequest(message)                                                                                  │
                               │    771 │   │   data = response.text.encode('utf8')                                                                                │
                               │    772 │   │   return ElementTree.fromstring(data) if data.strip() else None                                                      │
                               │    773                                                                                                                            │
                               ╰───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
                               BadRequest: (500) internal_server_error;                                                                                             
                               https://10-0-1-10.808cbc6741f14352b9c77bd45b676e74.plex.direct:32400/library/metadata/539544/children?excludeAllLeaves=1&index=None  
                               <html><head><title>Internal Server Error</title></head><body><h1>500 Internal Server Error</h1></body></html>                        
Error: Error running sync command: (500) internal_server_error; https://10-0-1-10.808cbc6741f14352b9c77bd45b676e74.plex.direct:32400/library/metadata/539544/children?excludeAllLeaves=1&index=None <html><head><title>Internal Server Error</title></head><body><h1>500 Internal Server Error</h1></body></html>

Expected behavior

sync

Steps to reproduce the behavior

plextractsync sync

Inspect of problematic items

No response

Workarounds

Exclude library until a solution is found

Install method

pipx

Config file contents

cache:
  path: /Users/alpacalypse/Library/Caches/PlexTraktSync/trakt_cache
excluded-libraries:
- Clips
- Fitness
- Music
- Music Videos
- Wrestling
config:
  dotenv_override: true
plex:
  timeout: 30
logging:
  append: false
  console_time: true
  debug: true
  filename: plextraktsync.log
  filter_loggers: null
  filter:
  - level: WARNING
  - level: WARNING
    message: not found on Trakt
  - message: because provider local has no external Id
  - message: because provider none has no external Id
  - message: Retry using search for specific Plex Episode
  - name: requests_cache.backends
  - name: requests_cache.backends.base
  - name: requests_cache.backends.sqlite
  - name: requests_cache.policy.actions
  - name: requests_cache.session
sync:
  plex_to_trakt:
    collection: true
    clear_collected: false
    ratings: true
    watched_status: true
    watchlist: true
  trakt_to_plex:
    liked_lists: false
    ratings: true
    watched_status: true
    watchlist: false
    watchlist_as_playlist: false
  rating_priority: plex
watch:
  add_collection: false
  remove_collection: false
  scrobble_threshold: 80
  username_filter: true
  media_progressbar: true
xbmc-providers:
  movies: imdb
  shows: tvdb

Version

0.27.10

Python Version

3.10.2

Operating System and Version

macOS-14.1.1

I have checked if identical issue already exists

Not really, see #1631

My apologies. I did see the similar issue, but didn't think it was identical. Thanks for looking into this!