【问题标题】:Signature does not match while trying to upload file to a temporary URL尝试将文件上传到临时 URL 时签名不匹配
【发布时间】:2015-09-29 21:24:45
【问题描述】:

我目前正在尝试构建一个 Web 服务来生成 Amazon S3 的临时 URL(这样我就不需要将凭证保存在其他地方)。如果我没有在 generate_url 方法的标头中包含“Content-MD5”键,它工作正常,但是一旦包含,我总是会得到同样的错误:

“我们计算的请求签名与您提供的签名不匹配。请检查您的密钥和签名方式。”

md5 的生成和包含方式如下:

md5checksum = key.compute_md5(open(filepath, "rb"))[0]
r = cli.session.post(serviceAddress + webService , data=json.dumps({"key": key, "size": os.path.getsize(filepath), "md5" : md5checksum}))

我也试过用

生成md5
md5checksum = hashlib.md5(open(filepath).read()).hexdigest()

在 web 服务端,临时 URL 是通过

生成的
headers={'Content-Length': length, 'Content-MD5': md5}
return self.conn.generate_url(expire, 'PUT', self.name, key, headers=headers, force_http=True)

我检查了 md5 在 URL 的生成和文件的上传之间没有变化。如果我只是删除 'Content-MD5': md5,它确实可以正常工作。

【问题讨论】:

    标签: python amazon-web-services amazon-s3


    【解决方案1】:

    根据 AWS 文档 Content-MD5 需要进行 Base64 编码:

    Content-MD5:消息的 base64 编码的 128 位 MD5 摘要 (没有标题)根据 RFC 1864

    来源:http://docs.aws.amazon.com/AmazonS3/latest/API/RESTObjectPUT.html

    【讨论】:

      猜你喜欢
      • 2020-05-21
      • 1970-01-01
      • 2015-11-01
      • 2019-06-01
      • 1970-01-01
      • 1970-01-01
      • 2022-08-20
      • 2023-03-15
      • 1970-01-01
      相关资源
      最近更新 更多