bodhisattva0743
bodhisattva0743

Reputation: 191

botocore.exceptions.ClientError An error occurred (SignatureDoesNotMatch) when calling the GetObject operation

While running the following code:

import boto3
BUCKET = 'bwd-plfb'

s3 = boto3.client('s3',use_ssl = False)

resp = s3.list_objects_v2(Bucket = BUCKET )

s3.download_file(BUCKET,'20171018/OK/OK_All.zip','test.zip')

I'm getting the following error:

   botocore.exceptions.ClientError: An error occurred 
   (SignatureDoesNotMatch) when calling the GetObject operation: The request 
   signature we calculated does not match the signature you provided. Check 
   your key and signing method.

What I've tried so far:

  1. Double checking Access key ID and Secret access key configured in aws cli (Running aws configure in command prompt) - They're correct.
  2. Trying to list bucket objects using boto3 - It worked successfully. The problem seems to be occuring when trying to download files.
  3. Using a chrome plugin to browse bucket contents and download files: chrome plugin It works successfully.

The interesting thing is downloading works for some files but not all. I downloaded a file which previously worked before 20 times in a row to see if the error was intermittent. It worked all 20 times. I did the same thing for a file which had not previously worked and it did not download any of the 20 times.

I saw some other posts on stackoverflow saying the api key & access key maybe incorrect. However, I don't believe that to be the case if I was able to list objects and download files (one's which did & did not work through boto3) using the Chrome S3 plugin.

Does anyone have any suggestions on what might be the issue here?

Thank You

Upvotes: 19

Views: 21512

Answers (4)

Igor Kołakowski
Igor Kołakowski

Reputation: 139

Using botocore directly worked for me

import botocore.session

endpoint_url = 'http://endpoint.com'
access_key = 'short-key'
secret_key = 'long-key'

session = botocore.session.Session()
s3 = session.create_client(
    's3',
    endpoint_url = endpoint_url,
    aws_access_key_id = access_key,
    aws_secret_access_key = secret_key,
    )

bucket_name = 'bucket'
s3_filename = 'foo.txt'
local_filename = 'bar.txt'

response = s3.get_object(Bucket=bucket_name, Key=s3_filename)
with open(local_filename, 'wb') as f:
    f.write(response['Body'].read())

Upvotes: 0

mes
mes

Reputation: 11

I encountered the error when my path was not correct. I had double slash // in my path. It removing one of the slashes fixed the error.

Upvotes: 1

TeamBlueEV
TeamBlueEV

Reputation: 11

I have encountered this myself. I download on a regular basis about 10 files daily from S3. I noticed that if the file is too large (~8MB), I get the SignatureDoesNotMatch error only for that file, but not the other files which are small in size. I then tried to use the shell "aws s3 cp" CLI command and got the same result. My co-worker suggested using "aws s3api get-object", which now works 100% of the time. However, I can't find the equivalent python script, so I'm stuck running the shell script. (s3.download_file or s3.download_fileobj don't work either.)

Upvotes: 1

Ryabchenko Alexander
Ryabchenko Alexander

Reputation: 12470

this error occurs when you use wrong/invalid secret key for s3

Upvotes: 12

Related Questions