如何在AWS Glue中捕获EntityNotFoundException异常?
如何捕获AWS Glue中获取不存在表时的EntityNotFoundException?
当我调用以下代码尝试从AWS Glue中获取不存在的数据库或表时:
glueContext.create_dynamic_frame.from_catalog(database='wrong_database_name', table_name='or_wrong_table_name')
会抛出如下异常:
An error occurred while calling o79.getCatalogSource.
: com.amazonaws.services.glue.model.EntityNotFoundException: Entity Not Found (Service: AWSGlue; Status Code: 400; Error Code: EntityNotFoundException; Request ID: 4f26a2ed-c7cc-48d4-bfe3-101816abe56d; Proxy: null
我尝试了以下两种捕获异常的方式,但都无效:
第一种方式:
import botocore try: glueContext.create_dynamic_frame.from_catalog(database='wrong_database_name', table_name='or_wrong_table_name') except botocore.exceptions.ClientError as err: if err.response['Error']['Code'] == 'EntityNotFoundException': # 处理逻辑 pass
第二种方式:
import boto3 glue = boto3.client('glue') try: glueContext.create_dynamic_frame.from_catalog(database='wrong_database_name', table_name='or_wrong_table_name') except glue.exceptions.EntityNotFoundException: # 处理逻辑 pass
第二种方式还要求为异常的__init__方法传入两个参数,这显然不太合理。有没有人遇到过这个问题?
内容的提问来源于stack exchange,提问作者OctaveParango
相关产品推荐
相关产品推荐

