change with conn: to with sqlite3.connect(self.db) as conn: