# Buggy code
def __init__(self, environ, populate_request=True, shallow=False):
    super(ReceiveModeRequest, self).__init__(environ, populate_request, shallow)
    self.web = environ["web"]

    # Is this a valid upload request?
    self.upload_request = False
    if self.method == "POST":
        if self.path == "/{}/upload".format(self.web.slug):
            self.upload_request = True
        else:
            if self.web.common.settings.get("public_mode"):
                if self.path == "/upload":
                    self.upload_request = True

    if self.upload_request:
        # A dictionary that maps filenames to the bytes uploaded so far
        self.progress = {}

        # Prevent new uploads if we've said so (timer expired)
        if self.web.receive_mode.can_upload:
            # Create an upload_id, attach it to the request
            self.upload_id = self.web.receive_mode.upload_count

            self.web.receive_mode.upload_count += 1

            # Figure out the content length
            try:
                self.content_length = int(self.headers["Content-Length"])
            except:
                self.content_length = 0

            print(
                "{}: {}".format(
                    datetime.now().strftime("%b %d, %I:%M%p"),
                    strings._("receive_mode_upload_starting").format(
                        self.web.common.human_readable_filesize(self.content_length)
                    ),
                )
            )

            # Don't tell the GUI that a request has started until we start receiving files
            self.told_gui_about_request = False

            self.previous_file = None


# Traceback (KeyError)
[Jan 07 2019 20:58:37] Onion.cleanup: trying to remove onion 5yym6w3kg4tof56umfy6a632nvtoc5dkkpkhj4zd2slqzp5wuiwml7yd
=> 2.4 MiB         video 1.mov[Jan 07 2019 20:58:37] ReceiveMode.update_primary_action
Traceback (most recent call last):
File "onionshare_gui/onionshare_gui.py", line 382, in timer_callback
mode.handle_request_progress(event)
File "onionshare_gui/mode/receive_mode/__init__.py", line 159, in handle_request_progress
'progress': event["data"]["progress"]
File "onionshare_gui/mode/history.py", line 451, in update
self.item_list.update(id, data)
File "onionshare_gui/mode/history.py", line 347, in update
self.items[id].update(data)
KeyError: 0
=> 2.4 MiB         video 1.movAbort trap: 6

# Fixed code
def __init__(self, environ, populate_request=True, shallow=False):
    super(ReceiveModeRequest, self).__init__(environ, populate_request, shallow)
    self.web = environ["web"]
    self.stop_q = environ["stop_q"]

    self.web.common.log("ReceiveModeRequest", "__init__")

    # Prevent running the close() method more than once
    self.closed = False

    # Is this a valid upload request?
    self.upload_request = False
    if self.method == "POST":
        if self.path == "/{}/upload".format(self.web.slug):
            self.upload_request = True
        else:
            if self.web.common.settings.get("public_mode"):
                if self.path == "/upload":
                    self.upload_request = True

    if self.upload_request:
        # A dictionary that maps filenames to the bytes uploaded so far
        self.progress = {}

        # Prevent new uploads if we've said so (timer expired)
        if self.web.receive_mode.can_upload:
            # Create an upload_id, attach it to the request
            self.upload_id = self.web.receive_mode.upload_count

            self.web.receive_mode.upload_count += 1

            # Figure out the content length
            try:
                self.content_length = int(self.headers["Content-Length"])
            except:
                self.content_length = 0

            print(
                "{}: {}".format(
                    datetime.now().strftime("%b %d, %I:%M%p"),
                    strings._("receive_mode_upload_starting").format(
                        self.web.common.human_readable_filesize(self.content_length)
                    ),
                )
            )

            # Don't tell the GUI that a request has started until we start receiving files
            self.told_gui_about_request = False

            self.previous_file = None