# Buggy code
def on_confirm_add_directory_dialog(self, action):
    if action == 0:
        if self.dialog.checkbox.isChecked():
            self.add_dir_to_channel(
                self.chosen_dir, callback=self.on_dir_added_to_channel
            )
        for torrent_file in self.selected_torrent_files:
            escaped_uri = "file:%s" % pathname2url(torrent_file.encode("utf-8"))
            self.perform_start_download_request(
                escaped_uri,
                self.window().tribler_settings["download_defaults"][
                    "anonymity_enabled"
                ],
                self.window().tribler_settings["download_defaults"][
                    "safeseeding_enabled"
                ],
                self.tribler_settings["download_defaults"]["saveas"],
                [],
                0,
            )

    if self.dialog:
        self.dialog.close_dialog()
        self.dialog = None


# Traceback (IOError)
ERROR   1563448884.34              rest_manager:83   (RESTRequest)  [Failure instance: Traceback: <type 'exceptions.IOError'>: [Errno 2] No such file or directory: u'/home/vader/\xd0\x97\xd0\xb0\xd0\xb3\xd1\x80\xd1\x83\xd0\xb7\xd0\xba\xd0\xb8/More torrents/(Dark Ambient Ambient Soundscape) [WEB] Victor Imaginator - \xd0\x94\xd0\xb8\xd1\x81\xd0\xba\xd0\xbe\xd0\xb3\xd1\x80\xd0\xb0\xd1\x84\xd0\xb8\xd1\x8f (2017-2018), 5 releases, FLAC (tracks), lossless [rutracker-5462864].torrent'
/home/vader/.local/lib/python2.7/site-packages/twisted/web/http.py:2115:_finishRequestBody
/home/vader/.local/lib/python2.7/site-packages/twisted/web/http.py:2190:allContentReceived
/home/vader/.local/lib/python2.7/site-packages/twisted/web/http.py:917:requestReceived
/home/vader/my_SRC/TRIBLER/tribler_ichorid/Tribler/Core/Modules/restapi/rest_manager.py:118:process
--- <exception caught here> ---
/home/vader/.local/lib/python2.7/site-packages/twisted/web/server.py:198:process
/home/vader/.local/lib/python2.7/site-packages/twisted/web/server.py:258:render
/home/vader/.local/lib/python2.7/site-packages/twisted/web/resource.py:250:render
/home/vader/my_SRC/TRIBLER/tribler_ichorid/Tribler/Core/Modules/restapi/downloads_endpoint.py:367:render_PUT
/home/vader/my_SRC/TRIBLER/tribler_ichorid/Tribler/Core/Session.py:220:start_download_from_uri
/home/vader/my_SRC/TRIBLER/tribler_ichorid/Tribler/Core/Libtorrent/LibtorrentMgr.py:599:start_download_from_uri
/home/vader/my_SRC/TRIBLER/tribler_ichorid/Tribler/Core/Libtorrent/LibtorrentMgr.py:641:start_download
/home/vader/my_SRC/TRIBLER/tribler_ichorid/Tribler/Core/TorrentDef.py:114:load
]
Traceback (most recent call last):
File "/home/vader/.local/lib/python2.7/site-packages/twisted/web/server.py", line 198, in process
self.render(resrc)
File "/home/vader/.local/lib/python2.7/site-packages/twisted/web/server.py", line 258, in render
body = resrc.render(self)
File "/home/vader/.local/lib/python2.7/site-packages/twisted/web/resource.py", line 250, in render
return m(request)
File "/home/vader/my_SRC/TRIBLER/tribler_ichorid/Tribler/Core/Modules/restapi/downloads_endpoint.py", line 367, in render_PUT
download_deferred = self.session.start_download_from_uri(download_uri, download_config)
File "/home/vader/my_SRC/TRIBLER/tribler_ichorid/Tribler/Core/Session.py", line 220, in start_download_from_uri
return self.lm.ltmgr.start_download_from_uri(uri, dconfig=download_config)
File "/home/vader/my_SRC/TRIBLER/tribler_ichorid/Tribler/Core/Libtorrent/LibtorrentMgr.py", line 599, in start_download_from_uri
return succeed(self.start_download(torrentfilename=argument, dconfig=dconfig))
File "/home/vader/my_SRC/TRIBLER/tribler_ichorid/Tribler/Core/Libtorrent/LibtorrentMgr.py", line 641, in start_download
tdef = TorrentDef.load(torrentfilename)
File "/home/vader/my_SRC/TRIBLER/tribler_ichorid/Tribler/Core/TorrentDef.py", line 114, in load
with open(filepath, "rb") as torrent_file:
IOError: [Errno 2] No such file or directory: u'/home/vader/\xd0\x97\xd0\xb0\xd0\xb3\xd1\x80\xd1\x83\xd0\xb7\xd0\xba\xd0\xb8/More torrents/(Dark Ambient Ambient Soundscape) [WEB] Victor Imaginator - \xd0\x94\xd0\xb8\xd1\x81\xd0\xba\xd0\xbe\xd0\xb3\xd1\x80\xd0\xb0\xd1\x84\xd0\xb8\xd1\x8f (2017-2018), 5 releases, FLAC (tracks), lossless [rutracker-5462864].torrent'

# Fixed code
def on_confirm_add_directory_dialog(self, action):
    if action == 0:
        if self.dialog.checkbox.isChecked():
            self.add_dir_to_channel(
                self.chosen_dir, callback=self.on_dir_added_to_channel
            )
        for torrent_file in self.selected_torrent_files:
            self.perform_start_download_request(
                "file:%s" % torrent_file,
                self.window().tribler_settings["download_defaults"][
                    "anonymity_enabled"
                ],
                self.window().tribler_settings["download_defaults"][
                    "safeseeding_enabled"
                ],
                self.tribler_settings["download_defaults"]["saveas"],
                [],
                0,
            )

    if self.dialog:
        self.dialog.close_dialog()
        self.dialog = None