Why am I getting Cannot operate on a closed database error in my SQLite Python code