mza921 / Plex-Auto-Collections

Python 3 script to automatically update Plex collections based off a configuration file
311 stars 29 forks source link

KeyError causing script to crash when adding to radarr #202

Open doctarrwho opened 3 years ago

doctarrwho commented 3 years ago

Seeing the script crash in the last few days. It used to work fine and nothing has changed in the config. The issue is easy to reproduce by adding the trakt trending list.

| Updating collection: * Trending on Trakt...
| Sync Mode: sync
|
| Processing trakt_trending: 25
| 25 Movies found on Trakt
| * Trending on Trakt Collection | = | The Little Things
| * Trending on Trakt Collection | = | Palmer
| * Trending on Trakt Collection | = | Wonder Woman 1984
| * Trending on Trakt Collection | = | News of the World
| * Trending on Trakt Collection | = | Tenet
| * Trending on Trakt Collection | = | Breach
| * Trending on Trakt Collection | = | Godzilla: King of the Monsters
| * Trending on Trakt Collection | = | Captain America: The Winter Soldier
| * Trending on Trakt Collection | = | Avengers: Endgame
| * Trending on Trakt Collection | = | Greenland
| * Trending on Trakt Collection | = | Promising Young Woman
| * Trending on Trakt Collection | = | The Matrix
| * Trending on Trakt Collection | = | Iron Man 2
| * Trending on Trakt Collection | = | Harry Potter and the Chamber of Secrets
| * Trending on Trakt Collection | = | Captain Marvel
| * Trending on Trakt Collection | = | Spider-Man: Far from Home
| * Trending on Trakt Collection | = | Bad Boys for Life
| * Trending on Trakt Collection | = | Shadow in the Cloud
| * Trending on Trakt Collection | = | Synchronic
| * Trending on Trakt Collection | + | Captain America: Civil War
| * Trending on Trakt Collection | = | The Lord of the Rings: The Return of the King
| * Trending on Trakt Collection | = | Harry Potter and the Sorcerer's Stone
| Processed 22 Movies
| 3 missing movies from Trakt Trending: Top 25
| Adding missing movies to Radarr
Traceback (most recent call last):
File "/app/plex_auto_collections.py", line 1026, in <module>
update_from_config(config_path, plex, True, args.no_meta, args.no_images)
File "/app/plex_auto_collections.py", line 685, in update_from_config
add_to_radarr(config_path, missing)
File "/app/radarr_tools.py", line 71, in add_to_radarr
print("| --- {}: {} {}".format(tmdb_title, response.json()[0]['errorMessage'], response.status_code))
KeyError: 0

Here's the config for the collection that is failing.

    "* Trending on Trakt":
        sort_title: "*100"
        trakt_trending: 25
        sync_mode: sync
        add_to_radarr: true
        trakt_list:
            - https://trakt.tv/users/giladg/lists/top-10-movies-of-the-week?sort=added,asc

This is the code throwing the exception:

        if response.status_code < 400:
            print("| +++ {}: Added to Radarr".format(tmdb_title))
        else:
            print("| --- {}: {} {}".format(tmdb_title, response.json()[0]['errorMessage'], response.status_code))

Radarr logs show the following two events when the exception occurs.

Radarr.Http.REST.BadRequestException: BadRequest: Invalid request body. The JSON value could not be converted to System.Int32. Path: $.tmdbid | LineNumber: 0 | BytePositionInLine: 74.
   at Radarr.Http.REST.RestModule`1.ReadResourceFromRequest(Boolean skipValidate, Boolean skipSharedValidate) in D:\a\1\s\src\Radarr.Http\REST\RestModule.cs:line 253
   at Radarr.Http.REST.RestModule`1.<set_CreateResource>b__43_0(Object options) in D:\a\1\s\src\Radarr.Http\REST\RestModule.cs:line 206
   at Nancy.NancyModule.<>c__DisplayClass38_0`1.<Post>b__0(Object args)
   at Nancy.NancyModule.<>c__DisplayClass40_0`1.<Post>b__0(Object args, CancellationToken ct)
   at Nancy.Routing.Route`1.Invoke(DynamicDictionary parameters, CancellationToken cancellationToken)
   at Nancy.Routing.DefaultRouteInvoker.Invoke(Route route, CancellationToken cancellationToken, DynamicDictionary parameters, NancyContext context)
   at Nancy.Routing.DefaultRequestDispatcher.Dispatch(NancyContext context, CancellationToken cancellationToken)
   at Nancy.NancyEngine.InvokeRequestLifeCycle(NancyContext context, CancellationToken cancellationToken, IPipelines pipelines)
Invalid request Validation failed: 
 -- Path: Invalid Path
 -- RootFolderPath: Invalid Path
 -- Title: 'Title' must not be empty.
 -- TmdbId: 'Tmdb Id' must not be empty.

Setting add_to_radarr to false for this collection does bypass the issue for the time being.

vaparr commented 3 years ago

I’m seeing the same issue on a different trakt collection

nicodog11 commented 3 years ago

I am having the same issue