# Buggy code
def run(request):
    """View the manifest."""
    try:
        directory = settings.BASE_DIR  # BASE DIR
        md5 = request.GET["md5"]  # MD5
        typ = request.GET["type"]  # APK or SOURCE
        binary = request.GET["bin"]
        match = re.match("^[0-9a-f]{32}$", md5)
        if match and (typ in ["eclipse", "studio", "apk"]) and (binary in ["1", "0"]):
            app_dir = os.path.join(settings.UPLD_DIR, md5 + "/")  # APP DIRECTORY
            tools_dir = os.path.join(directory, "StaticAnalyzer/tools/")  # TOOLS DIR
            if binary == "1":
                is_binary = True
            elif binary == "0":
                is_binary = False
            app_path = os.path.join(app_dir, md5 + ".apk")
            manifest = read_manifest(app_dir, app_path, tools_dir, typ, is_binary)
            context = {
                "title": "AndroidManifest.xml",
                "file": "AndroidManifest.xml",
                "dat": manifest,
            }
            template = "static_analysis/view_mani.html"
            return render(request, template, context)
    except:
        PrintException("[ERROR] Viewing AndroidManifest.xml")
        return HttpResponseRedirect("/error/")


# 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 run(request):
    """View the manifest."""
    try:
        directory = settings.BASE_DIR  # BASE DIR
        md5 = request.GET["md5"]  # MD5
        typ = request.GET["type"]  # APK or SOURCE
        binary = request.GET["bin"]
        match = re.match("^[0-9a-f]{32}$", md5)
        if match and (typ in ["eclipse", "studio", "apk"]) and (binary in ["1", "0"]):
            app_dir = os.path.join(settings.UPLD_DIR, md5 + "/")  # APP DIRECTORY
            tools_dir = os.path.join(directory, "StaticAnalyzer/tools/")  # TOOLS DIR
            if binary == "1":
                is_binary = True
            elif binary == "0":
                is_binary = False
            app_path = os.path.join(app_dir, md5 + ".apk")
            manifest = read_manifest(app_dir, app_path, tools_dir, typ, is_binary)
            context = {
                "title": "AndroidManifest.xml",
                "file": "AndroidManifest.xml",
                "dat": manifest,
            }
            template = "static_analysis/view_mani.html"
            return render(request, template, context)
    except:
        PrintException("Viewing AndroidManifest.xml")
        return print_n_send_error_response(request, "Error Viewing AndroidManifest.xml")