Python “如何处理错误”;请求的操作无法验证。请查看下面的Boto例外情况以了解更多详细信息。”;?

Python “如何处理错误”;请求的操作无法验证。请查看下面的Boto例外情况以了解更多详细信息。”;?,python,amazon-web-services,boto,amazon-cloudformation,Python,Amazon Web Services,Boto,Amazon Cloudformation,我正在尝试为一些内部AWS脚本创建一些模拟测试。在创建boto3资源并尝试验证不存在的堆栈时,我在运行python脚本时遇到以下错误: “请求的操作无法验证。有关详细信息,请查看下面的Boto异常。” 这将是伟大的,除了…没有像错误提到的“下面的Boto异常”,只有命令提示符。这是什么意思 下面是一些示例代码: def function(): resource = boto3.resource('cloudformation') verify_stack(resource, 'M

我正在尝试为一些内部AWS脚本创建一些模拟测试。在创建boto3资源并尝试验证不存在的堆栈时,我在运行python脚本时遇到以下错误:

“请求的操作无法验证。有关详细信息,请查看下面的Boto异常。”

这将是伟大的,除了…没有像错误提到的“下面的Boto异常”,只有命令提示符。这是什么意思

下面是一些示例代码:

def function():
    resource = boto3.resource('cloudformation')
    verify_stack(resource, 'MockStack')

def verify_stack(session, stackName):
      try:
          stack = session.meta.client.describe_stacks(StackName=stack_name)

      except:
          return {}

      else:
          return stack

仅供参考,堆栈“MockStack”不存在,我正在测试以确保这一点。我的一部分人认为我得到的错误是告诉我堆栈不存在,这是正确的。这可能是问题吗?

找到了解决我问题的方法。我在try/except语句中包装了
verify\u stack
函数,发现了一个ClientError。以下是正确的代码:

try:
    session = boto3.Session()
    resource = session.resource('cloudformation')

    sqs_template = {
        "AWSTemplateFormatVersion": "2010-09-09",
        "Resources": {
            "QueueGroup": {

            "Type": "AWS::SQS::Queue",
            "Properties": {
                "QueueName": "my-queue",
                "VisibilityTimeout": 60,
            }
            },
        },
    }

    sqs_template_json = json.dumps(sqs_template)

    resource.create_stack(
        StackName="mock_stack",
        TemplateBody=sqs_template_json,
    )

    response = resource.verify_stack(resource, 'mock_stack')

    print  response

except ClientError as error:
    print error.message

找到了解决我问题的方法。我在try/except语句中包装了
verify\u stack
函数,发现了一个ClientError。以下是正确的代码:

try:
    session = boto3.Session()
    resource = session.resource('cloudformation')

    sqs_template = {
        "AWSTemplateFormatVersion": "2010-09-09",
        "Resources": {
            "QueueGroup": {

            "Type": "AWS::SQS::Queue",
            "Properties": {
                "QueueName": "my-queue",
                "VisibilityTimeout": 60,
            }
            },
        },
    }

    sqs_template_json = json.dumps(sqs_template)

    resource.create_stack(
        StackName="mock_stack",
        TemplateBody=sqs_template_json,
    )

    response = resource.verify_stack(resource, 'mock_stack')

    print  response

except ClientError as error:
    print error.message