How to export sqlite and python exceptions log using Import Error

Asked

Viewed 16 times

1

I am using Python and giving import of sqlite3 library and sqlite3 giving import in Error for exception handling!

import sqlite3
from sqlite3 import Error

def errorlog(erro):
    errlog = open("err_log.txt", 'a')
    errlog.write(erro)
    errlog.close()


def conexaoBanco():
    con = None
    try:
        con = sqlite3.connect('banco.db')
    except Error as er:
        errorlog(er)
    return con

However the variable er does not contain a string! generating this error:

TypeError: write() argument must be str, not OperationalError
  • That’s what the error message says, the function argument should be str and not an instance of OperationalError. Testing errlog.write(erro.message)

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.