From 06b4e417e20011b3cf29821d2f819e4323b61568 Mon Sep 17 00:00:00 2001 From: Aman Sachan Date: Sat, 20 Jun 2026 00:03:53 +0000 Subject: [PATCH] fix: replace bare except with ClientError in glue_crawler.py --- .../glue_crawler.py | 21 ++++++++++--------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/AWS_Glue_Crawler_and_Data_Catalog_with_Python/glue_crawler.py b/AWS_Glue_Crawler_and_Data_Catalog_with_Python/glue_crawler.py index e9ea932..c4211f8 100644 --- a/AWS_Glue_Crawler_and_Data_Catalog_with_Python/glue_crawler.py +++ b/AWS_Glue_Crawler_and_Data_Catalog_with_Python/glue_crawler.py @@ -1,10 +1,11 @@ import boto3 +from botocore.exceptions import ClientError ## Change With Your Own Bucket BUCKET_NAME = "glueworkshop-357171621133-us-west-2" client = boto3.client('glue') -# Create database +# Create database try: response = client.create_database( DatabaseInput={ @@ -13,10 +14,10 @@ } ) print("Successfully created database") -except: - print("error in creating database") +except ClientError as e: + print(f"error in creating database: {e.response['Error']['Code']} - {e.response['Error']['Message']}") -# Create Glue Crawler +# Create Glue Crawler try: response = client.create_crawler( Name='python-lab1', @@ -25,18 +26,18 @@ Targets={ 'S3Targets': [ { - 'Path': 's3://{BUCKET_NAME}/input/lab1/csv'.format(BUCKET_NAME = BUCKET_NAME), + 'Path': 's3://{BUCKET_NAME}/input/lab1/csv'.format(BUCKET_NAME=BUCKET_NAME), }, { - 'Path': 's3://{BUCKET_NAME}/input/lab5/json'.format(BUCKET_NAME = BUCKET_NAME), + 'Path': 's3://{BUCKET_NAME}/input/lab5/json'.format(BUCKET_NAME=BUCKET_NAME), } ] }, TablePrefix='python_' ) print("Successfully created crawler") -except: - print("error in creating crawler") +except ClientError as e: + print(f"error in creating crawler: {e.response['Error']['Code']} - {e.response['Error']['Message']}") # This is the command to start the Crawler try: @@ -44,5 +45,5 @@ Name='python-lab1' ) print("Successfully started crawler") -except: - print("error in starting crawler") +except ClientError as e: + print(f"error in starting crawler: {e.response['Error']['Code']} - {e.response['Error']['Message']}")