Finally works properly. Needed the line "db.autocommit(True)" after connecting to the database.