简体   繁体   中英

boto3 generate_presigned_url SignatureDoesNotMatch

I want to download files from S3 in a web application. Therefore I create an URL using boto3 generate_presigned_url

import boto3

s3Client = boto3.client(
    's3',
    region_name='eu-central-1',
    config=boto3.session.Config(signature_version='v4'),
    aws_access_key_id='xxxxxxxxxxxxxxx',
    aws_secret_access_key='xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
)

url = s3Client.generate_presigned_url(
    'get_object',
    Params={'Bucket': 'bucketname', 'Key': 'test.txt'},
    ExpiresIn=100)

but always get this error message back:

<Error>
  <Code>SignatureDoesNotMatch</Code>
  <Message>The request signature we calculated does not match the
  signature you provided. Check your key and signing method.</Message>

any ideas what to do?

signature_version='s3v4' works for me. I got the same error if use signature_version='v4'

s3_client = boto3.client('s3', region_name=REGION, 
    config=Config(signature_version='s3v4'),
    aws_access_key_id=AWS_ACCESS_KEY_ID, 
   aws_secret_access_key=AWS_SECRET_ACCESS_KEY)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM