运行我的代码时,我收到此异常(打印用于调试的类):
An error occurred (DBInstanceNotFound) when calling the DescribeDBInstances operation: DBInstance <instance name> not found.
<class 'botocore.errorfactory.DBInstanceNotFoundFault'>
我想像这样正确处理异常:
from botocore.exceptions import DBInstanceNotFoundFault
from botocore.errorfactory import DBInstanceNotFoundFault
try:
<fetch info about db instance>
except DBInstanceNotFoundFault as e:
<handle error>
不幸的是 DBInstanceNotFoundFault 既不存在于 botocore.exceptions 中,也不存在于 botocore.errorfactory 中。 我已经为 DBInstanceNotFoundFault 克隆了boto3以及botocore和grep'd,但却找不到它。
如何导入?
答案 0 :(得分:7)
对于boto3例外,您实际上并未导入错误 - 而是通过客户端访问它。看看这个:https://github.com/boto/boto3/issues/1195#issuecomment-317108970
import boto3
rds = boto3.client('rds')
try:
...
except rds.exceptions.DBInstanceNotFoundFault:
...