# Buggy code
def items(self):
    if self._items is None:
        try:
            r = self.session.get(
                "http://www.imdb.com/list/export?list_id=%s&author_id=%s"
                % (self.list_id, self.user_id)
            )
        except RequestException as e:
            raise PluginError(e.args[0])
        lines = r.iter_lines(decode_unicode=True)
        # Throw away first line with headers
        next(lines)
        self._items = []
        for row in csv.reader(lines):
            row = [cell for cell in row]
            log.debug("parsing line from csv: %s", ", ".join(row))
            if not len(row) == 16:
                log.debug("no movie row detected, skipping. %s", ", ".join(row))
                continue
            entry = Entry(
                {
                    "title": "%s (%s)" % (row[5], row[11])
                    if row[11] != "????"
                    else "%s" % row[5],
                    "url": row[15],
                    "imdb_id": row[1],
                    "imdb_url": row[15],
                    "imdb_list_position": int(row[0]),
                    "imdb_list_created": datetime.strptime(
                        row[2], "%a %b %d %H:%M:%S %Y"
                    )
                    if row[2]
                    else None,
                    "imdb_list_modified": datetime.strptime(
                        row[3], "%a %b %d %H:%M:%S %Y"
                    )
                    if row[3]
                    else None,
                    "imdb_list_description": row[4],
                    "imdb_name": row[5],
                    "movie_name": row[5],
                    "imdb_year": int(row[11]) if row[11] != "????" else None,
                    "movie_year": int(row[11]) if row[11] != "????" else None,
                    "imdb_score": float(row[9]) if row[9] else None,
                    "imdb_user_score": float(row[8]) if row[8] else None,
                    "imdb_votes": int(row[13]) if row[13] else None,
                    "imdb_genres": [genre.strip() for genre in row[12].split(",")],
                }
            )
            self._items.append(entry)
    return self._items


# Traceback (UnicodeEncodeError)
2016-04-25 14:16 DEBUG    scheduler                     task finished executing: watchlist
2016-04-25 14:16 DEBUG    manager       watchlist       Not running db cleanup, last run 2016-04-18 18:17:04
2016-04-25 14:16 DEBUG    task          watchlist       executing watchlist
2016-04-25 14:16 DEBUG    utils.requests watchlist       Fetching https://www.imdb.com/ap/signin?openid.return_to=https%3A%2F%2Fwww.imdb.com%2Fap-signin-handler&amp;openid.identity=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0%2Fidentifier_select&amp;openid.assoc_handle=imdb_mobile_us&amp;openid.mode=checkid_setup&amp;openid.claimed_id=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0%2Fidentifier_select&amp;openid.ns=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0
2016-04-25 14:16 VERBOSE  utils.requests watchlist       Waiting 3.76 seconds until next request to imdb.com
2016-04-25 14:16 DEBUG    utils.requests watchlist       Fetching https://www.imdb.com/ap/signin
2016-04-25 14:16 VERBOSE  utils.requests watchlist       Waiting 4.22 seconds until next request to imdb.com
2016-04-25 14:16 DEBUG    utils.requests watchlist       Fetching http://www.imdb.com/profile
2016-04-25 14:16 VERBOSE  utils.requests watchlist       Waiting 4.51 seconds until next request to imdb.com
2016-04-25 14:16 DEBUG    utils.requests watchlist       Fetching http://www.imdb.com/list/_ajax/watchlist_has
2016-04-25 14:16 VERBOSE  utils.requests watchlist       Waiting 4.62 seconds until next request to imdb.com
2016-04-25 14:16 DEBUG    utils.requests watchlist       Fetching http://www.imdb.com/list/export?list_id=ls000306550&amp;author_id=ur1345105
2016-04-25 14:16 DEBUG    imdb_list     watchlist       parsing line from csv: 1, tt1321870, Tue Jul  3 02:44:29 2012, Tue Jul  3 02:44:29 2012, , Gangster Squad, Feature Film, Ruben Fleischer, , 6.7, 113, 2013, action, crime, drama, thriller, 170997, 2013-01-07, http://www.imdb.com/title/tt1321870/
2016-04-25 14:16 DEBUG    imdb_list     watchlist       parsing line from csv: 2, tt1212419, Thu Jul  5 05:40:53 2012, Thu Jul  5 05:40:53 2012, , Hereafter, Feature Film, Clint Eastwood, , 6.5, 129, 2010, drama, fantasy, 79283, 2010-09-12, http://www.imdb.com/title/tt1212419/
2016-04-25 14:16 DEBUG    imdb_list     watchlist       parsing line from csv: 3, tt1480656, Thu Jul  5 05:45:19 2012, Thu Jul  5 05:45:19 2012, , Cosmopolis, Feature Film, David Cronenberg, , 5.0, 109, 2012, drama, 37149, 2012-05-25, http://www.imdb.com/title/tt1480656/
2016-04-25 14:16 DEBUG    imdb_list     watchlist       parsing line from csv: 4, tt1446192, Thu Jul  5 05:49:28 2012, Thu Jul  5 05:49:28 2012, , Rise of the Guardians, Feature Film, Peter Ramsey, , 7.3, 97, 2012, animation, adventure, family, fantasy, 120274, 2012-10-10, http://www.imdb.com/title/tt1446192/
2016-04-25 14:16 DEBUG    imdb_list     watchlist       parsing line from csv: 5, tt1623205, Sun Jul 15 10:48:18 2012, Sun Jul 15 10:48:18 2012, , Oz the Great and Powerful, Feature Film, Sam Raimi, , 6.4, 130, 2013, adventure, family, fantasy, 172820, 2013-02-14, http://www.imdb.com/title/tt1623205/
2016-04-25 14:16 DEBUG    imdb_list     watchlist       parsing line from csv: 6, tt2223842, Tue Jul 24 13:38:44 2012, Tue Jul 24 13:38:44 2012, , The Prototype, Feature Film, Andrew Will, , , , ????, action, sci_fi, , , http://www.imdb.com/title/tt2223842/
2016-04-25 14:16 DEBUG    imdb_list     watchlist       parsing line from csv: 7, tt2097307, Tue Aug  7 12:44:36 2012, Tue Aug  7 12:44:36 2012, , Hit and Run, Feature Film, David Palmer, Dax Shepard, , 6.1, 100, 2012, action, comedy, romance, 28838, 2012-08-02, http://www.imdb.com/title/tt2097307/
2016-04-25 14:16 DEBUG    imdb_list     watchlist       parsing line from csv: 8, tt1905041, Tue May  7 23:20:16 2013, Tue May  7 23:20:16 2013, , Fast &amp; Furious 6, Feature Film, Justin Lin, , 7.2, 130, 2013, action, crime, thriller, 294713, 2013-05-07, http://www.imdb.com/title/tt1905041/
2016-04-25 14:16 DEBUG    imdb_list     watchlist       parsing line from csv: 9, tt1583421, Sun Jul 28 04:40:55 2013, Sun Jul 28 04:40:55 2013, , G.I. Joe: Retaliation, Feature Film, Jon M. Chu, , 5.8, 110, 2013, action, adventure, sci_fi, thriller, 143440, 2013-03-11, http://www.imdb.com/title/tt1583421/
2016-04-25 14:16 DEBUG    imdb_list     watchlist       parsing line from csv: 10, tt2167202, Wed Aug 21 14:05:15 2013, Wed Aug 21 14:05:15 2013, , Getaway, Feature Film, Courtney Solomon, , 4.4, 90, 2013, action, crime, thriller, 19171, 2013-08-26, http://www.imdb.com/title/tt2167202/
2016-04-25 14:16 DEBUG    imdb_list     watchlist       parsing line from csv: 11, tt1821694, Wed Aug 21 14:05:50 2013, Wed Aug 21 14:05:50 2013, , RED 2, Feature Film, Dean Parisot, , 6.7, 116, 2013, action, comedy, crime, thriller, 121564, 2013-07-18, http://www.imdb.com/title/tt1821694/
2016-04-25 14:16 DEBUG    imdb_list     watchlist       parsing line from csv: 12, tt1253863, Wed Aug 21 14:09:03 2013, Wed Aug 21 14:09:03 2013, , 300: Rise of an Empire, Feature Film, Noam Murro, , 6.2, 102, 2014, action, drama, fantasy, war, 219116, 2014-03-04, http://www.imdb.com/title/tt1253863/
2016-04-25 14:16 CRITICAL task          watchlist       BUG: Unhandled error in plugin imdb_list: 'ascii' codec can't encode character u'\xe0' in position 81: ordinal not in range(128)
Traceback (most recent call last):
File "/usr/local/flexget/env/lib/python2.7/site-packages/flexget/task.py", line 443, in __run_plugin
return method(*args, **kwargs)
File "/usr/local/flexget/env/lib/python2.7/site-packages/flexget/event.py", line 23, in __call__
return self.func(*args, **kwargs)
File "/usr/local/flexget/env/lib/python2.7/site-packages/flexget/plugins/list/imdb_list.py", line 222, in on_task_input
return list(self.get_list(config))
File "/usr/local/flexget/env/lib/python2.7/site-packages/flexget/plugins/list/imdb_list.py", line 155, in __iter__
return iter(self.items)
File "/usr/local/flexget/env/lib/python2.7/site-packages/flexget/plugins/list/imdb_list.py", line 112, in items
for row in csv.reader(lines):
UnicodeEncodeError: 'ascii' codec can't encode character u'\xe0' in position 81: ordinal not in range(128)

# Fixed code
def items(self):
    if self._items is None:
        try:
            r = self.session.get(
                "http://www.imdb.com/list/export?list_id=%s&author_id=%s"
                % (self.list_id, self.user_id)
            )
        except RequestException as e:
            raise PluginError(e.args[0])
        lines = r.iter_lines(decode_unicode=True)
        # Throw away first line with headers
        next(lines)
        self._items = []
        for row in csv_reader(lines):
            log.debug("parsing line from csv: %s", ", ".join(row))
            if not len(row) == 16:
                log.debug("no movie row detected, skipping. %s", ", ".join(row))
                continue
            entry = Entry(
                {
                    "title": "%s (%s)" % (row[5], row[11])
                    if row[11] != "????"
                    else "%s" % row[5],
                    "url": row[15],
                    "imdb_id": row[1],
                    "imdb_url": row[15],
                    "imdb_list_position": int(row[0]),
                    "imdb_list_created": datetime.strptime(
                        row[2], "%a %b %d %H:%M:%S %Y"
                    )
                    if row[2]
                    else None,
                    "imdb_list_modified": datetime.strptime(
                        row[3], "%a %b %d %H:%M:%S %Y"
                    )
                    if row[3]
                    else None,
                    "imdb_list_description": row[4],
                    "imdb_name": row[5],
                    "movie_name": row[5],
                    "imdb_year": int(row[11]) if row[11] != "????" else None,
                    "movie_year": int(row[11]) if row[11] != "????" else None,
                    "imdb_score": float(row[9]) if row[9] else None,
                    "imdb_user_score": float(row[8]) if row[8] else None,
                    "imdb_votes": int(row[13]) if row[13] else None,
                    "imdb_genres": [genre.strip() for genre in row[12].split(",")],
                }
            )
            self._items.append(entry)
    return self._items