# Buggy code
def read_sqlite(sqlite_file):
    """Read SQlite File"""
    try:
        logger.info("Dumping SQLITE Database")
        data = ""
        con = sqlite3.connect(sqlite_file)
        cur = con.cursor()
        cur.execute("SELECT name FROM sqlite_master WHERE type='table';")
        tables = cur.fetchall()
        for table in tables:
            data += (
                "\nTABLE: "
                + str(table[0]).decode("utf8", "ignore")
                + " \n=====================================================\n"
            )
            cur.execute("PRAGMA table_info('%s')" % table)
            rows = cur.fetchall()
            head = ""
            for row in rows:
                head += str(row[1]).decode("utf8", "ignore") + " | "
            data += (
                head
                + " \n========================================"
                + "=============================\n"
            )
            cur.execute("SELECT * FROM '%s'" % table)
            rows = cur.fetchall()
            for row in rows:
                dat = ""
                for item in row:
                    dat += str(item).decode("utf8", "ignore") + " | "
                data += dat + "\n"
        return data
    except:
        PrintException("[ERROR] Dumping SQLITE Database")


# 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 read_sqlite(sqlite_file):
    """Read SQlite File"""
    try:
        logger.info("Dumping SQLITE Database")
        data = ""
        con = sqlite3.connect(sqlite_file)
        cur = con.cursor()
        cur.execute("SELECT name FROM sqlite_master WHERE type='table';")
        tables = cur.fetchall()
        for table in tables:
            data += (
                "\nTABLE: "
                + str(table[0]).decode("utf8", "ignore")
                + " \n=====================================================\n"
            )
            cur.execute("PRAGMA table_info('%s')" % table)
            rows = cur.fetchall()
            head = ""
            for row in rows:
                head += str(row[1]).decode("utf8", "ignore") + " | "
            data += (
                head
                + " \n========================================"
                + "=============================\n"
            )
            cur.execute("SELECT * FROM '%s'" % table)
            rows = cur.fetchall()
            for row in rows:
                dat = ""
                for item in row:
                    dat += str(item).decode("utf8", "ignore") + " | "
                data += dat + "\n"
        return data
    except:
        PrintException("Dumping SQLITE Database")