# Buggy code
def get_context_from_analysis_ipa(app_dict, info_dict, bin_dict, files, sfiles):
    """Get the context for IPA from analysis results"""
    try:
        context = {
            "title": "Static Analysis",
            "file_name": app_dict["file_name"],
            "size": app_dict["size"],
            "md5": app_dict["md5_hash"],
            "sha1": app_dict["sha1"],
            "sha256": app_dict["sha256"],
            "plist": info_dict["plist_xml"],
            "bin_name": info_dict["bin_name"],
            "id": info_dict["id"],
            "build": info_dict["build"],
            "version": info_dict["bundle_version_name"],
            "sdk": info_dict["sdk"],
            "pltfm": info_dict["pltfm"],
            "min": info_dict["min"],
            "bin_anal": bin_dict["bin_res"],
            "libs": bin_dict["libs"],
            "files": files,
            "file_analysis": sfiles,
            "strings": bin_dict["strings"],
            "permissions": info_dict["permissions"],
            "insecure_connections": info_dict["inseccon"],
            "bundle_name": info_dict["bundle_name"],
            "bundle_url_types": info_dict["bundle_url_types"],
            "bundle_supported_platforms": info_dict["bundle_supported_platforms"],
            "bundle_localizations": info_dict["bundle_localizations"],
        }
        return context
    except:
        PrintException("[ERROR] Rendering to Template")


# 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 get_context_from_analysis_ipa(app_dict, info_dict, bin_dict, files, sfiles):
    """Get the context for IPA from analysis results"""
    try:
        context = {
            "title": "Static Analysis",
            "file_name": app_dict["file_name"],
            "size": app_dict["size"],
            "md5": app_dict["md5_hash"],
            "sha1": app_dict["sha1"],
            "sha256": app_dict["sha256"],
            "plist": info_dict["plist_xml"],
            "bin_name": info_dict["bin_name"],
            "id": info_dict["id"],
            "build": info_dict["build"],
            "version": info_dict["bundle_version_name"],
            "sdk": info_dict["sdk"],
            "pltfm": info_dict["pltfm"],
            "min": info_dict["min"],
            "bin_anal": bin_dict["bin_res"],
            "libs": bin_dict["libs"],
            "files": files,
            "file_analysis": sfiles,
            "strings": bin_dict["strings"],
            "permissions": info_dict["permissions"],
            "insecure_connections": info_dict["inseccon"],
            "bundle_name": info_dict["bundle_name"],
            "bundle_url_types": info_dict["bundle_url_types"],
            "bundle_supported_platforms": info_dict["bundle_supported_platforms"],
            "bundle_localizations": info_dict["bundle_localizations"],
        }
        return context
    except:
        PrintException("Rendering to Template")