# Buggy code
def list_entries(config, test_mode=None):
    log.verbose("Connecting to CouchPotato to retrieve movie list.")
    active_movies_url = CouchPotatoBase.build_url(
        config.get("base_url"), "active", config.get("port"), config.get("api_key")
    )
    active_movies_json = CouchPotatoBase.get_json(active_movies_url)
    # Gets profile and quality lists if include_data is TRUE
    if config.get("include_data"):
        log.verbose("Connecting to CouchPotato to retrieve profile data.")
        profile_url = CouchPotatoBase.build_url(
            config.get("base_url"),
            "profiles",
            config.get("port"),
            config.get("api_key"),
        )
        profile_json = CouchPotatoBase.get_json(profile_url)

    entries = []
    for movie in active_movies_json["movies"]:
        quality_req = ""
        log.debug("movie data: {}".format(movie))
        if movie["status"] == "active":
            if config.get("include_data") and profile_json:
                for profile in profile_json["list"]:
                    if (
                        profile["_id"] == movie["profile_id"]
                    ):  # Matches movie profile with profile JSON
                        quality_req = CouchPotatoBase.quality_requirement_builder(
                            profile
                        )
            entry = Entry(
                title=movie["title"],
                url="",
                imdb_id=movie["info"].get("imdb"),
                tmdb_id=movie["info"].get("tmdb_id"),
                quality_req=quality_req,
                couchpotato_id=movie.get("_id"),
            )
            if entry.isvalid():
                log.debug("returning entry %s", entry)
                entries.append(entry)
            else:
                log.error("Invalid entry created? %s", entry)
                continue
            # Test mode logging
            if entry and test_mode:
                log.info("Test mode. Entry includes:")
                for key, value in entry.items():
                    log.info("     %s: %s", key.capitalize(), value)

    return entries


# Traceback (KeyError)
CP LOG
2016-10-12 10:47 VERBOSE  task_queue                    There are 1 tasks to execute. Shutdown will commence when they have completed.
2016-10-12 10:47 VERBOSE  couchpotato_list queue_movies_couchpotato Connecting to CouchPotato to retrieve movie list.
2016-10-12 10:47 VERBOSE  couchpotato_list queue_movies_couchpotato Connecting to CouchPotato to retrieve profile data.
2016-10-12 10:47 CRITICAL task          queue_movies_couchpotato BUG: Unhandled error in plugin couchpotato_list: u'status'
2016-10-12 10:47 CRITICAL manager       queue_movies_couchpotato An unexpected crash has occurred. Writing crash report to /root/crash_report.2016.10.12.104721788205.log. Please verify you are running the la
test version of flexget by using "flexget -V" from CLI or by using version_checker plugin at http://flexget.com/wiki/Plugins/version_checker. You are currently using version 2.3.42
2016-10-12 10:47 WARNING  task          queue_movies_couchpotato Aborting task (plugin: couchpotato_list)



CP crash

2016-10-12 10:46 DEBUG    manager                       Figuring out config load paths
2016-10-12 10:46 DEBUG    manager                       Found config: /root/config.yml
2016-10-12 10:46 DEBUG    manager                       Config file /root/config.yml selected
2016-10-12 10:47 VERBOSE  task_queue                    There are 1 tasks to execute. Shutdown will commence when they have completed.
2016-10-12 10:47 VERBOSE  couchpotato_list queue_movies_couchpotato Connecting to CouchPotato to retrieve movie list.
2016-10-12 10:47 VERBOSE  couchpotato_list queue_movies_couchpotato Connecting to CouchPotato to retrieve profile data.
2016-10-12 10:47 CRITICAL task          queue_movies_couchpotato BUG: Unhandled error in plugin couchpotato_list: u'status'
Traceback (most recent call last):
File "/usr/lib/python2.7/site-packages/flexget/task.py", line 477, in __run_plugin
return method(*args, **kwargs)
File "/usr/lib/python2.7/site-packages/flexget/event.py", line 23, in __call__
return self.func(*args, **kwargs)
File "/usr/lib/python2.7/site-packages/flexget/plugins/list/couchpotato_list.py", line 242, in on_task_input
return list(CouchPotatoSet(config))
File "/usr/lib/python2.7/site-packages/flexget/plugins/list/couchpotato_list.py", line 195, in __iter__
return (entry for entry in self.movies)
File "/usr/lib/python2.7/site-packages/flexget/plugins/list/couchpotato_list.py", line 180, in movies
self._movies = CouchPotatoBase.list_entries(self.config)
File "/usr/lib/python2.7/site-packages/flexget/plugins/list/couchpotato_list.py", line 115, in list_entries
if movie['status'] == 'active':
KeyError: u'status'

# Fixed code
def list_entries(config, test_mode=None):
    log.verbose("Connecting to CouchPotato to retrieve movie list.")
    active_movies_url = CouchPotatoBase.build_url(
        config.get("base_url"), "active", config.get("port"), config.get("api_key")
    )
    active_movies_json = CouchPotatoBase.get_json(active_movies_url)
    # Gets profile and quality lists if include_data is TRUE
    if config.get("include_data"):
        log.verbose("Connecting to CouchPotato to retrieve profile data.")
        profile_url = CouchPotatoBase.build_url(
            config.get("base_url"),
            "profiles",
            config.get("port"),
            config.get("api_key"),
        )
        profile_json = CouchPotatoBase.get_json(profile_url)

    entries = []
    for movie in active_movies_json["movies"]:
        # Related to #1444, corrupt data from CP
        if not all([movie.get("status"), movie.get("title"), movie.get("info")]):
            log.warning("corrupt movie data received, skipping")
            continue
        quality_req = ""
        log.debug("movie data: %s", movie)
        if movie["status"] == "active":
            if config.get("include_data") and profile_json:
                for profile in profile_json["list"]:
                    if (
                        profile["_id"] == movie["profile_id"]
                    ):  # Matches movie profile with profile JSON
                        quality_req = CouchPotatoBase.quality_requirement_builder(
                            profile
                        )
            entry = Entry(
                title=movie["title"],
                url="",
                imdb_id=movie["info"].get("imdb"),
                tmdb_id=movie["info"].get("tmdb_id"),
                quality_req=quality_req,
                couchpotato_id=movie.get("_id"),
            )
            if entry.isvalid():
                log.debug("returning entry %s", entry)
                entries.append(entry)
            else:
                log.error("Invalid entry created? %s", entry)
                continue
            # Test mode logging
            if entry and test_mode:
                log.info("Test mode. Entry includes:")
                for key, value in entry.items():
                    log.info("     %s: %s", key.capitalize(), value)

    return entries