# Buggy code
def feed_playlist(username):
    # fetch all user playlists
    playlists = spotify.user_playlists(username)
    links = []
    check = 1
    # iterate over user playlists
    while True:
        for playlist in playlists["items"]:
            print(
                str(check)
                + ". "
                + misc.fix_encoding(playlist["name"])
                + " ("
                + str(playlist["tracks"]["total"])
                + " tracks)"
            )
            links.append(playlist)
            check += 1
        if playlists["next"]:
            playlists = spotify.next(playlists)
        else:
            break

    print("")
    # let user select playlist
    playlist = misc.input_link(links)
    # fetch detailed information for playlist
    results = spotify.user_playlist(
        playlist["owner"]["id"], playlist["id"], fields="tracks,next"
    )
    print("")
    # slugify removes any special characters
    file = slugify(playlist["name"], ok="-_()[]{}") + ".txt"
    print("Feeding " + str(playlist["tracks"]["total"]) + " tracks to " + file)

    tracks = results["tracks"]
    with open(file, "a") as fout:
        while True:
            for item in tracks["items"]:
                track = item["track"]
                try:
                    fout.write(track["external_urls"]["spotify"] + "\n")
                except KeyError:
                    title = track["name"] + " by " + track["artists"][0]["name"]
                    print("Skipping track " + title + " (local only?)")
            # 1 page = 50 results
            # check if there are more pages
            if tracks["next"]:
                tracks = spotify.next(tracks)
            else:
                break


# Traceback (TypeError)
linus@sony-vaio ~/spotify-downloader $ python3 spotdl.py -u spotify
1. Today's Top Hits (50 tracks)
2. RapCaviar (63 tracks)
...
276. Disco Fever (50 tracks)
277. Tegan and Sara: Pride (27 tracks)
Traceback (most recent call last):
File "spotdl.py", line 303, in <module>
feed_playlist(username=args.username)
File "spotdl.py", line 124, in feed_playlist
print(str(check) + '. ' + misc.fix_encoding(playlist['name']) + ' (' + str(playlist['tracks']['total']) + ' tracks)')
TypeError: Can't convert 'NoneType' object to str implicitly

# Fixed code
def feed_playlist(username):
    # fetch all user playlists
    playlists = spotify.user_playlists(username)
    links = []
    check = 1
    # iterate over user playlists
    while True:
        for playlist in playlists["items"]:
            # In rare cases, playlists may not be found, so playlists['next'] is
            # None. Skip these. Also see Issue #91.
            if playlist["name"] is not None:
                print(
                    str(check)
                    + ". "
                    + misc.fix_encoding(playlist["name"])
                    + " ("
                    + str(playlist["tracks"]["total"])
                    + " tracks)"
                )
                links.append(playlist)
                check += 1
        if playlists["next"]:
            playlists = spotify.next(playlists)
        else:
            break

    print("")
    # let user select playlist
    playlist = misc.input_link(links)
    # fetch detailed information for playlist
    results = spotify.user_playlist(
        playlist["owner"]["id"], playlist["id"], fields="tracks,next"
    )
    print("")
    # slugify removes any special characters
    file = slugify(playlist["name"], ok="-_()[]{}") + ".txt"
    print("Feeding " + str(playlist["tracks"]["total"]) + " tracks to " + file)

    tracks = results["tracks"]
    with open(file, "a") as fout:
        while True:
            for item in tracks["items"]:
                track = item["track"]
                try:
                    fout.write(track["external_urls"]["spotify"] + "\n")
                except KeyError:
                    title = track["name"] + " by " + track["artists"][0]["name"]
                    print("Skipping track " + title + " (local only?)")
            # 1 page = 50 results
            # check if there are more pages
            if tracks["next"]:
                tracks = spotify.next(tracks)
            else:
                break