2017-09-05 5 views
1

Je voudrais import le exception qui se produit lorsqu'un paramètre boto3ssm est introuvable avec get_parameter. J'essaie d'ajouter une fonctionnalité supplémentaire ssm à la bibliothèque moto, mais je suis perplexe à ce stade.Comment puis-je importer l'exception boto3 ssm ParameterNotFound?

>>> 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 

Cependant, le Exception ne peut pas être importé, et ne semble pas exister dans le code botocore. Comment puis-je importer cette exception?

Répondre

2

De Botocore Error Handling

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']