'Django: continuing block after exception

How to continue the execution of a block after an exception. I have two vmware servers running I have created two functions, one that refreshes the information coming from the server and the other that populates the database.

Except that when one of the servers does not respond an error occurs and the refresh is not done.

def vm_refresh(request):
    vmware_list = Vmware.objects.all()
    for i in vmware_list:
        vmwarepopulatevm(i)
        i.save()
    # ...

def vcsapopulatevm(vmware):
    # ...
    req1 = vmrequestsget()
    if 'value' in req1.json().keys():
        for i in my req1.json()['value']:
            VirtualMachine.objects.update_or_create(vm=i['vm']
                                                    vmware=vmware,
                                                    defaults=i
                                                    )
    # ...

I tried somethink like this and it's works

try:
    vmwarepopulatevm(i)
    i.save()
except Exception:
    pass

But I want to create a generic function because I will have to use it more often



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source