[BUG] KeyError gallore
BrutuZ opened this issue · 4 comments
Describe the bug
3 unhandled exceptions in a row during a stream.
Desktop (please complete the following information):
- OS and Version: W10
- Python Version: 3.11
- Player and Version: Plex
- Trakt Scrobbler Version: 1.7.0b2
To Reproduce
Steps to reproduce the behavior:
- Start Playing a Plex Movie entry with the title indicated in the log
(Entry is using the new Plex Movie Agent)
Log file
Click to see log contents
2024-08-03 19:31:24,614 - DEBUG - MainThread - notifier - Notifications enabled for categories: exception, misc, scrobble.stop, trakt
2024-08-03 19:31:24,618 - INFO - notify_loop - notifier - Starting notif loop
2024-08-03 19:31:24,619 - DEBUG - MainThread - notifier - Notif actions enabled for categories:
2024-08-03 19:31:25,364 - DEBUG - MainThread - mediainfo_remap - Read 10 remap rules from %AppData%\trakt-scrobbler\remap_rules.toml
2024-08-03 19:31:25,367 - INFO - MainThread - scrobbler - Started scrobbler thread.
2024-08-03 19:31:25,382 - DEBUG - MainThread - monitor - Autoloaded mpc-hc port = 13579
2024-08-03 19:31:25,382 - INFO - MainThread - monitor - Started monitor for mpc-hc
2024-08-03 19:31:25,383 - INFO - MainThread - monitor - Started monitor for plex
2024-08-03 19:31:27,432 - DEBUG - plex - monitor - action=scrobble
2024-08-03 19:31:27,433 - DEBUG - plex - monitor - {'state': 1, 'progress': 51.69, 'media_info': {'type': 'movie', 'title': 'Ghostbusters: Frozen Empire', 'year': 2024}, 'updated_at': 1722724287.4320993}
2024-08-03 19:31:27,434 - DEBUG - scrobbler - scrobbler - Scrobbling pause at 51.69% for Ghostbusters: Frozen Empire
2024-08-03 19:31:27,435 - ERROR - scrobbler - __init__ - Unhandled exception
Traceback (most recent call last):
File "%LocalAppData%\pipx\pipx\venvs\trakt-scrobbler\Lib\site-packages\trakt_scrobbler\trakt_interface.py", line 71, in get_ids
trakt_id = media_info['trakt_id']
~~~~~~~~~~^^^^^^^^^^^^
KeyError: 'trakt_id'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "%LocalAppData%\pipx\pipx\venvs\trakt-scrobbler\Lib\site-packages\trakt_scrobbler\trakt_interface.py", line 74, in get_ids
trakt_slug = media_info['trakt_slug']
~~~~~~~~~~^^^^^^^^^^^^^^
KeyError: 'trakt_slug'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Program Files\Python311\Lib\threading.py", line 1038, in _bootstrap_inner
self.run()
File "%LocalAppData%\pipx\pipx\venvs\trakt-scrobbler\Lib\site-packages\trakt_scrobbler\scrobbler.py", line 36, in run
self.scrobble(verb, data)
File "%LocalAppData%\pipx\pipx\venvs\trakt-scrobbler\Lib\site-packages\trakt_scrobbler\scrobbler.py", line 78, in scrobble
resp = trakt.scrobble(verb, **data)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "%LocalAppData%\pipx\pipx\venvs\trakt-scrobbler\Lib\site-packages\trakt_scrobbler\trakt_interface.py", line 108, in scrobble
scrobble_data = prepare_scrobble_data(media_info)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "%LocalAppData%\pipx\pipx\venvs\trakt-scrobbler\Lib\site-packages\trakt_scrobbler\trakt_interface.py", line 92, in prepare_scrobble_data
ids = get_ids(media_info)
^^^^^^^^^^^^^^^^^^^
File "%LocalAppData%\pipx\pipx\venvs\trakt-scrobbler\Lib\site-packages\trakt_scrobbler\trakt_interface.py", line 77, in get_ids
trakt_id = get_trakt_id(title, media_info['type'], media_info.get('year'))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "%LocalAppData%\pipx\pipx\venvs\trakt-scrobbler\Lib\site-packages\trakt_scrobbler\trakt_interface.py", line 38, in get_trakt_id
trakt_id = trakt_cache[required_type].get(key)
~~~~~~~~~~~^^^^^^^^^^^^^^^
KeyError: 'movie'
2024-08-03 19:31:29,471 - INFO - mpc-hc - monitor - Unable to connect to mpc-hc. Ensure that the web interface is running.
Seems like your trakt_cache.json
file is in a bad state somehow. Have you edited it manually?
Most of the KeyError
s are just spurious in this case, the one that matters is the last one. It says there is no movie
key in the cache dict. Which seems very unlikely to happen automatically.
The fix would be to just delete that file from https://github.com/iamkroot/trakt-scrobbler/wiki/FAQs#where-is-the-log-fileother-data-stored and restart the scrobbler with trakts start -r
.
I did have to edit it at some point because of a wrong match.
Took me forever to realize that cache file was the reason trakt-scrobbler would scrobble the wrong show no matter how many times I edited the entry and restarted the server 😅
Took me forever to realize that cache file was the reason trakt-scrobbler would scrobble the wrong show no matter how many times I edited the entry and restarted the server 😅
What exactly was the edit that cause such a bad experience? Did movie
get changed to show
or something?
Going to close this one, bug is due to user error here. We can definitely improve UX by adding better validations, but that should be a separate issue.