In case exception is kind-of a normal flow, you should consider checking for the key here before trying to access one, e.g.:

    vm = data['name_vm'] if 'name_vm' in data else None
    vm_libvirt.VM(vm)

General rule of thumb is to have as linear code as possible