Python 在执行Azure移动资源时是否有跳过错误的方法?

Python 在执行Azure移动资源时是否有跳过错误的方法?,python,azure,azure-sdk,azure-sdk-python,Python,Azure,Azure Sdk,Azure Sdk Python,我正在尝试将大量Azure资源从Azure资源组移动到Azure资源组 我的代码如下所示: for i in resource_client.resources.list(filter=f"tagName eq 'run_id' and tagValue eq '{RUN_ID}'"): print_item(i) ids.append(i.id) targetRG = resource_client.resource_groups.get(resourc

我正在尝试将大量Azure资源从Azure资源组移动到Azure资源组

我的代码如下所示:

for i in resource_client.resources.list(filter=f"tagName eq 'run_id' and tagValue eq '{RUN_ID}'"): 
    print_item(i)
    ids.append(i.id)

targetRG = resource_client.resource_groups.get(resource_group_name=DELETE_GROUP_NAME)

for id in ids:
    try:
        poller = resource_client.resources.move_resources(source_resource_group_name=SOURCE_GROUP_NAME, target_resource_group=targetRG.id, resources=id)                           
        rg_move_result = poller.result()
    except:
        pass

我不希望使用第二个循环,而是批量执行,但是如果在移动过程中出现任何错误,它就会失败。有没有一种方法可以做到这一切,只需跳过错误?

基本上,您可以尝试使用下面的代码结构来实现您想要的:

for xxx:
    try:
        #Move single resource in this place.
    except:
        #Use continue to out and continue the loop.
        continue

顺便说一下,如果您检查源代码,“move_resources()”中的“resources”类型应该是列表类型。

基本上,您可以尝试使用下面的代码结构来实现您想要的:

for xxx:
    try:
        #Move single resource in this place.
    except:
        #Use continue to out and continue the loop.
        continue

顺便说一句,如果你检查源代码,“move_resources()”中的“resources”类型应该是列表类型。

Gotcha-我想我想找的是一种方法,告诉Azure这样做,尝试做所有事情,只跳过(或报告错误)那些不起作用的。@aronchick嗨,我不确定Gotcha的含义。。。我的答案是你想要的吗?我只是想说我明白,但我的代码已经做到了。我要寻找的是azure(不是python)固有的东西,它接受一组批量命令并全部执行,跳过任何错误(但在最后报告错误)。明白了-我想我要寻找的是一种方法,告诉azure去做它试图做的一切,而只是跳过(或报告错误)只为那些不起作用的人。@aronchick嗨,我不确定gotcha的意思。。。我的答案是你想要的吗?我只是想说我明白,但我的代码已经做到了。我要寻找的是azure(不是python)的原生版本,它接受一组批量命令并全部执行,跳过任何错误(但在最后报告错误)。