1
import os
import boto3
import json
from datetime import datetime,timedelta

s3 = boto3.client('s3', aws_access_key_id="<access_key>",
                    aws_secret_access_key="<secret_key>")
##my_bucket = s3.Bucket('grn-amazon')
filename_withdate=(datetime.now()-timedelta(days=6)).strftime ("%d%b%Y")
filename_withdate = filename_withdate+'_Consolidated.csv'
Source_filename = filename_withdate
dest_filename = filename_withdate
try:
##    s3.download_file('grn-amazon',complt_filename,'01FEB2020_Consolidated.csv')
    s3.download_file('grn-amazon',Source_filename,dest_filename)
    print("Download Completed")
except botocore.exception.ClientErrors as e:
    if e.response['Error']['Code'] == '404':
        print('The Object does not exists!!')
    else:
        raise

Getting below error after running above code. Kindly help on this.. Passing Source and Destination file name as parameter in S3 attributes...

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "C:\Cloudtail\CT\SQL Scripts\python\GRN_S3_dwnld.py", line 17, in except botocore.exception.ClientErrors as e: NameError: name 'botocore' is not defined

0

2 Answers 2

1

Figured out an error, its not boto3 error. Filename in Capital letter like 01FEB2020, my source file is taking like 01Feb2020.

Change above date with upper() function

filename_withdate=((datetime.now()-timedelta(days=6)).strftime ("%d%b%Y").upper())

Thanks all to your valuable time and responses.

Sign up to request clarification or add additional context in comments.

Comments

0

Add this to the top of your Python program:

from botocore.exceptions import ClientError

Change

except botocore.exception.ClientErrors as e:

into:

except botocore.exception.ClientError as e:

1 Comment

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.