# Buggy code
def handle_sqlite(sfile):
    """SQLite Dump - Readable Text"""
    logger.info("SQLite DB Extraction")
    try:
        data = ""
        con = sq.connect(sfile)
        cur = con.cursor()
        cur.execute("SELECT name FROM sqlite_master WHERE type='table';")
        tables = cur.fetchall()
        for table in tables:
            data += (
                "\nTABLE: "
                + table[0]
                + " \n=====================================================\n"
            )
            cur.execute("PRAGMA table_info('%s')" % table)
            rows = cur.fetchall()
            head = ""
            for sq_row in rows:
                elm_data = sq_row[1]
                head += elm_data + " | "
            data += (
                head
                + " \n============================================"
                + "=========================\n"
            )
            cur.execute("SELECT * FROM '%s'" % table)
            rows = cur.fetchall()
            for sq_row in rows:
                dat = ""
                for each_row in sq_row:
                    dat += str(each_row) + " | "
                data += dat + "\n"
        return data
    except:
        PrintException("[ERROR] SQLite DB Extraction")


# 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 handle_sqlite(sfile):
    """SQLite Dump - Readable Text"""
    logger.info("SQLite DB Extraction")
    try:
        data = ""
        con = sq.connect(sfile)
        cur = con.cursor()
        cur.execute("SELECT name FROM sqlite_master WHERE type='table';")
        tables = cur.fetchall()
        for table in tables:
            data += (
                "\nTABLE: "
                + table[0]
                + " \n=====================================================\n"
            )
            cur.execute("PRAGMA table_info('%s')" % table)
            rows = cur.fetchall()
            head = ""
            for sq_row in rows:
                elm_data = sq_row[1]
                head += elm_data + " | "
            data += (
                head
                + " \n============================================"
                + "=========================\n"
            )
            cur.execute("SELECT * FROM '%s'" % table)
            rows = cur.fetchall()
            for sq_row in rows:
                dat = ""
                for each_row in sq_row:
                    dat += str(each_row) + " | "
                data += dat + "\n"
        return data
    except:
        PrintException("SQLite DB Extraction")