# Buggy code
def _parse_xml(app_dir):
    """Parse the AppxManifest file to get basic informations."""
    logger.info("Starting Binary Analysis - XML")
    xml_file = os.path.join(app_dir, "AppxManifest.xml")
    xml_dic = {
        "version": "",
        "arch": "",
        "app_name": "",
        "pub_name": "",
        "compiler_version": "",
        "visual_studio_version": "",
        "visual_studio_edition": "",
        "target_os": "",
        "appx_dll_version": "",
        "proj_guid": "",
        "opti_tool": "",
        "target_run": "",
    }

    try:
        logger.info("Reading AppxManifest")
        config = etree.XMLParser(  # pylint: disable-msg=E1101
            remove_blank_text=True, resolve_entities=False
        )
        xml = etree.XML(open(xml_file, "rb").read(), config)  # pylint: disable-msg=E1101
        for child in xml.getchildren():
            # } to prevent conflict with PhoneIdentity..
            if isinstance(child.tag, str) and child.tag.endswith("}Identity"):
                xml_dic["version"] = child.get("Version")
                xml_dic["arch"] = child.get("ProcessorArchitecture")
            elif isinstance(child.tag, str) and child.tag.endswith("Properties"):
                for sub_child in child.getchildren():
                    if sub_child.tag.endswith("}DisplayName"):
                        # TODO(Needed? Compare to existing app_name)
                        xml_dic["app_name"] = sub_child.text
                    elif sub_child.tag.endswith("}PublisherDisplayName"):
                        xml_dic["pub_name"] = sub_child.text
            elif isinstance(child.tag, str) and child.tag.endswith("}Metadata"):
                xml_dic = __parse_xml_metadata(xml_dic, child)
    except:
        PrintException("[ERROR] - Reading from AppxManifest.xml")
    return xml_dic


# Traceback (KeyError)
[INFO] 08/Feb/2019 16:17:54 - VM Starting
[INFO] 08/Feb/2019 16:17:55 - "POST /DynamicAnalyzer/ HTTP/1.1" 200 32400
[INFO] 08/Feb/2019 16:17:55 - "GET /static/css/devices.min.css HTTP/1.1" 200 44241
[INFO] 08/Feb/2019 16:17:55 - "GET /download/screen/screen.png HTTP/1.1" 302 0
[DEBUG] 08/Feb/2019 16:17:55 - Exception while resolving variable 'exp' in template 'general/error.html'.
Traceback (most recent call last):
File "/home/userhome/Mobile-Security-Framework-MobSF/venv/lib/python3.6/site-packages/django/template/base.py", line 829, in _resolve_lookup
current = current[bit]
File "/home/userhome/Mobile-Security-Framework-MobSF/venv/lib/python3.6/site-packages/django/template/context.py", line 83, in __getitem__
raise KeyError(key)
KeyError: 'exp'

During handling of the above exception, another exception occurred:

# Fixed code
def _parse_xml(app_dir):
    """Parse the AppxManifest file to get basic informations."""
    logger.info("Starting Binary Analysis - XML")
    xml_file = os.path.join(app_dir, "AppxManifest.xml")
    xml_dic = {
        "version": "",
        "arch": "",
        "app_name": "",
        "pub_name": "",
        "compiler_version": "",
        "visual_studio_version": "",
        "visual_studio_edition": "",
        "target_os": "",
        "appx_dll_version": "",
        "proj_guid": "",
        "opti_tool": "",
        "target_run": "",
    }

    try:
        logger.info("Reading AppxManifest")
        config = etree.XMLParser(  # pylint: disable-msg=E1101
            remove_blank_text=True, resolve_entities=False
        )
        xml = etree.XML(open(xml_file, "rb").read(), config)  # pylint: disable-msg=E1101
        for child in xml.getchildren():
            # } to prevent conflict with PhoneIdentity..
            if isinstance(child.tag, str) and child.tag.endswith("}Identity"):
                xml_dic["version"] = child.get("Version")
                xml_dic["arch"] = child.get("ProcessorArchitecture")
            elif isinstance(child.tag, str) and child.tag.endswith("Properties"):
                for sub_child in child.getchildren():
                    if sub_child.tag.endswith("}DisplayName"):
                        # TODO(Needed? Compare to existing app_name)
                        xml_dic["app_name"] = sub_child.text
                    elif sub_child.tag.endswith("}PublisherDisplayName"):
                        xml_dic["pub_name"] = sub_child.text
            elif isinstance(child.tag, str) and child.tag.endswith("}Metadata"):
                xml_dic = __parse_xml_metadata(xml_dic, child)
    except:
        PrintException("Reading from AppxManifest.xml")
    return xml_dic