BOTO3 - generate_presigned_url for `put_object` return `我们计算的请求签名与您提供的签名不匹配` [英] BOTO3 - generate_presigned_url for `put_object` return `The request signature we calculated does not match the signature you provided`

查看:33
本文介绍了BOTO3 - generate_presigned_url for `put_object` return `我们计算的请求签名与您提供的签名不匹配`的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个预先签名的 url,以帮助一些客户上传文件.这是我目前正在运行的测试脚本

I'm trying to create a presigned url that will help some customers to upload files . Here my test script that is currently working

# Get the service client.
s3 = boto3.client('s3')
boto3.set_stream_logger(name='botocore')

# Generate the URL to get 'key-name' from 'bucket-name'
url = s3.generate_presigned_url(
    ClientMethod='put_object',
    Params={
        'Bucket': s3_bucket_name,
        'Key': test_key,
    }    
)

files = StringIO("asdfasdfasdf")
response = requests.put(url, data=files)

print(str(response.content))

但是如果我要添加:

`ACL': 'public-read' 

Params(或在put_object 文档 我从服务器收到:

to Params (or add some metadata following the information in the put_object documentation I receive back from the server:

The request signature we calculated does not match the signature you provided. Check your key and signing method.

<小时>

我也在 BOTO3 上打开了一个问题:https://github.com/boto/boto3/issues/1722

推荐答案

这在 github issue https://github.com/boto/boto3/issues/934

This is covered in the github issue https://github.com/boto/boto3/issues/934

要上传对象,您应该使用 generate_presigned_post.有几个参数不能嵌入到url中,这些参数是通过那个方法返回给你的.

For uploading an object, you should use generate_presigned_post. There are several parameters that cannot be embedded within the url, and those are returned to you by that method.

这篇关于BOTO3 - generate_presigned_url for `put_object` return `我们计算的请求签名与您提供的签名不匹配`的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆