zal*_*314 14 python amazon-web-services botocore boto3 moto
我想import的exception是,当发生boto3 ssm不与发现的参数get_parameter.我正在尝试为库添加一些额外的ssm功能moto,但我在这一点上很难过.
>>> 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
Run Code Online (Sandbox Code Playgroud)
但是,Exception无法导入,并且似乎不存在于botocore代码中.如何导入此例外?
小智 17
mc = boto3.client('ssm')
try:
...
except mc.exceptions.ParameterNotFound:
...
Run Code Online (Sandbox Code Playgroud)
hel*_*loV 13
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']
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3482 次 |
| 最近记录: |