# Buggy code
def perform_start_download_request(
    self,
    uri,
    anon_download,
    safe_seeding,
    destination,
    selected_files,
    total_files=0,
    callback=None,
):
    selected_files_uri = ""
    if len(selected_files) != total_files:  # Not all files included
        selected_files_uri = "&" + "".join(
            "selected_files[]=%s&" % file for file in selected_files
        )[:-1].encode("utf-8")

    anon_hops = (
        int(self.tribler_settings["Tribler"]["default_number_hops"])
        if anon_download
        else 0
    )
    safe_seeding = 1 if safe_seeding else 0
    post_data = "uri=%s&anon_hops=%d&safe_seeding=%d&destination=%s%s" % (
        uri,
        anon_hops,
        safe_seeding,
        destination,
        selected_files_uri,
    )
    post_data = post_data.encode(
        "utf-8"
    )  # We need to send bytes in the request, not unicode

    request_mgr = TriblerRequestManager()
    self.pending_requests[request_mgr.request_id] = request_mgr
    request_mgr.perform_request(
        "downloads",
        callback if callback else self.on_download_added,
        method="PUT",
        data=post_data,
    )

    # Save the download location to the GUI settings
    current_settings = get_gui_setting(
        self.gui_settings, "recent_download_locations", ""
    )
    recent_locations = current_settings.split(",") if len(current_settings) > 0 else []
    encoded_destination = destination.encode("hex")
    if encoded_destination in recent_locations:
        recent_locations.remove(encoded_destination)
    recent_locations.insert(0, encoded_destination)

    if len(recent_locations) > 5:
        recent_locations = recent_locations[:5]

    self.gui_settings.setValue("recent_download_locations", ",".join(recent_locations))


# Traceback (KeyError)
Traceback (most recent call last):
File "/home/tribler/tribler/TriblerGUI/widgets/downloadsdetailstabwidget.py", line 163, in <lambda>
exclude_action.triggered.connect(lambda: self.on_files_excluded(selected_files_info))
File "/home/tribler/tribler/TriblerGUI/widgets/downloadsdetailstabwidget.py", line 188, in on_files_excluded
self.set_included_files(included_list)
File "/home/tribler/tribler/TriblerGUI/widgets/downloadsdetailstabwidget.py", line 191, in set_included_files
data_str = ''.join(u"selected_files[]=%s&amp;" % quote_plus(file) for file in files)[:-1].encode('utf-8')
File "/home/tribler/tribler/TriblerGUI/widgets/downloadsdetailstabwidget.py", line 191, in <genexpr>
data_str = ''.join(u"selected_files[]=%s&amp;" % quote_plus(file) for file in files)[:-1].encode('utf-8')
File "/usr/lib/python2.7/urllib.py", line 1299, in quote_plus
s = quote(s, safe + ' ')
File "/usr/lib/python2.7/urllib.py", line 1294, in quote
return ''.join(map(quoter, s))
KeyError: u'\u0413'

# Fixed code
def perform_start_download_request(
    self,
    uri,
    anon_download,
    safe_seeding,
    destination,
    selected_files,
    total_files=0,
    callback=None,
):
    selected_files_uri = ""
    if len(selected_files) != total_files:  # Not all files included
        selected_files_uri = (
            "&" + "".join("selected_files[]=%s&" % file for file in selected_files)[:-1]
        )

    anon_hops = (
        int(self.tribler_settings["Tribler"]["default_number_hops"])
        if anon_download
        else 0
    )
    safe_seeding = 1 if safe_seeding else 0
    post_data = "uri=%s&anon_hops=%d&safe_seeding=%d&destination=%s%s" % (
        uri,
        anon_hops,
        safe_seeding,
        destination,
        selected_files_uri,
    )
    post_data = post_data.encode(
        "utf-8"
    )  # We need to send bytes in the request, not unicode

    request_mgr = TriblerRequestManager()
    self.pending_requests[request_mgr.request_id] = request_mgr
    request_mgr.perform_request(
        "downloads",
        callback if callback else self.on_download_added,
        method="PUT",
        data=post_data,
    )

    # Save the download location to the GUI settings
    current_settings = get_gui_setting(
        self.gui_settings, "recent_download_locations", ""
    )
    recent_locations = current_settings.split(",") if len(current_settings) > 0 else []
    encoded_destination = destination.encode("hex")
    if encoded_destination in recent_locations:
        recent_locations.remove(encoded_destination)
    recent_locations.insert(0, encoded_destination)

    if len(recent_locations) > 5:
        recent_locations = recent_locations[:5]

    self.gui_settings.setValue("recent_download_locations", ",".join(recent_locations))