本文介绍了如何导入boto3 ssm ParameterNotFound异常?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想importget_parameter中找不到boto3 ssm参数时出现的exception.我正在尝试向moto库中添加一些额外的ssm功能,但现在我很困惑.

I would like to import the exception that occurs when a boto3 ssm parameter is not found with get_parameter. I'm trying to add some extra ssm functionality to the moto library, but I am stumped at this point.

>>> import boto3
>>> ssm = boto3.client('ssm')
>>> try:
        ssm.get_parameter(Name='not_found')
    except Exception as e:
        print(type(e))
<class 'botocore.errorfactory.ParameterNotFound'>
>>> from botocore.errorfactory import ParameterNotFound
ImportError: cannot import name 'ParameterNotFound'
>>> import botocore.errorfactory.ParameterNotFound
ModuleNotFoundError: No module named 'botocore.errorfactory.ParameterNotFound'; 'botocore.errorfactory' is not a package

但是,Exception无法导入,并且在botocore代码中似乎不存在.如何导入此异常?

However, the Exception cannot be imported, and does not appear to exist in the botocore code. How can I import this exception?

推荐答案

来自 Botocore错误处理

import boto3
from botocore.exceptions import ClientError

ssm = boto3.client('ssm')
try:
    ssm.get_parameter(Name='not_found')
except ClientError as e:
    print e.response['Error']['Code']

这篇关于如何导入boto3 ssm ParameterNotFound异常?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-30 20:30