# Buggy code
def entry_complete(self, e, task=None):
    if not e.accepted:
        log.warning("Not removing %s entry %s", e.state, e["title"])
    elif "remove_url" not in e:
        log.warning("No remove_url for %s, skipping", e["title"])
    elif task.options.test:
        log.info("Would remove from watchlist: %s", e["title"])
    else:
        log.info("Removing from watchlist: %s", e["title"])

        headers = {
            "Origin": "https://mijn.npo.nl/",
            "Referer": "https://mijn.npo.nl/profiel/kijklijst",
            "X-CSRF-Token": self.csrf_token,
            "X-Requested-With": "XMLHttpRequest",
        }

        try:
            delete_response = requests.delete(e["remove_url"], headers=headers)
        except requests.HTTPError as error:
            log.error(
                "Failed to remove %s, got status %s",
                e["title"],
                error.response.status_code,
            )
        else:
            if delete_response.status_code != requests.codes.ok:
                log.warning(
                    "Failed to remove %s, got status %s",
                    e["title"],
                    delete_response.status_code,
                )


# Traceback (AttributeError)
2017-07-05 20:31 CRITICAL task tv-journaal BUG: Unhandled error in plugin npo_watchlist: 'NoneType' object has no attribute 'find'
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/flexget/task.py", line 486, in __run_plugin
return method(*args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/flexget/event.py", line 23, in call
return self.func(*args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/flexget/plugins/input/npo_watchlist.py", line 326, in on_task_input
entries += self._get_favorites_entries(task, config)
File "/usr/local/lib/python2.7/dist-packages/flexget/plugins/input/npo_watchlist.py", line 318, in _get_favorites_entries
series_info = self._get_series_info(task, config, series_name, url)
File "/usr/local/lib/python2.7/dist-packages/flexget/plugins/input/npo_watchlist.py", line 180, in _get_series_info
series_info['npo_url'] = tvseries.find('a', itemprop='url')['href']
AttributeError: 'NoneType' object has no attribute 'find'

# Fixed code
def entry_complete(self, e, task=None):
    if not e.accepted:
        log.warning("Not removing %s entry %s", e.state, e["title"])
    elif "remove_url" not in e:
        log.warning("No remove_url for %s, skipping", e["title"])
    elif task.options.test:
        log.info("Would remove from watchlist: %s", e["title"])
    else:
        log.info("Removing from watchlist: %s", e["title"])

        headers = {
            "Origin": "https://www.npo.nl",
            "Referer": "https://www.npo.nl/mijn_npo",
            "X-XSRF-TOKEN": requests.cookies["XSRF-TOKEN"],
            "X-Requested-With": "XMLHttpRequest",
        }

        try:
            delete_response = requests.post(
                e["remove_url"], headers=headers, cookies=requests.cookies
            )
        except HTTPError as error:
            log.error(
                "Failed to remove %s, got status %s",
                e["title"],
                error.response.status_code,
            )
        else:
            if delete_response.status_code != requests.codes.ok:
                log.warning(
                    "Failed to remove %s, got status %s",
                    e["title"],
                    delete_response.status_code,
                )