简体   繁体   English

如何从`ibm_boto3`调用`generate_presigned_post`?

[英]how do I call `generate_presigned_post` from `ibm_boto3`?

I create credentials (tried both write and manager) on the web interface and include {"HMAC":true}我在 web 接口上创建凭据(尝试写入和管理器)并包含{"HMAC":true}

I have used these credentials for more basic actions such as put_object and upload_file successfully.我已将这些凭据用于更基本的操作,例如put_objectupload_file成功。

However, I cannot get generate_presigned_post to work.但是,我无法让generate_presigned_post工作。 It generates the following error:它会产生以下错误:

ibm_botocore.exceptions.UnsupportedSignatureVersionError: Signature version is not supported: oauth-presign-post ibm_botocore.exceptions.UnsupportedSignatureVersionError:不支持签名版本:oauth-presign-post

I run the following code,我运行以下代码,

import ibm_boto3
from ibm_botocore.client import Config

class COSPresignedURL():
    def __init__(self, config):
        cfg = Config(signature_version='oauth', s3={"payload_signing_enabled":True})
        self.cos = ibm_boto3.client(
            's3',
            ibm_api_key_id=config['api_key'],
            ibm_service_instance_id=config['instance_id'],
            ibm_auth_endpoint=config['auth_endpoint'],
            endpoint_url=config['url_endpoint'],
            config=cfg)

    def generate(self, bucket, key, Fields=None, Conditions=None, ExpiresIn=300):
        return self.cos.generate_presigned_post(bucket, key, Fields, Conditions, ExpiresIn)


def main():
    config = {
        "api_key" : "VALUE OF apikey FROM CLOUD CREDENTIALS",
        "instance_id" : "VALUE OF resource_instance_id FROM CLOUD CREDENTIALS",
        "auth_endpoint" : "https://iam.cloud.ibm.com/identity/token",
        "url_endpoint" : "https://s3.eu-de.cloud-object-storage.appdomain.cloud"
    }

    bucket = 'somebucket'

    poster = COSPresignedURL(config)
    uri = poster.generate(bucket, 'somekey')
    print(f'{uri}')


if __name__ == '__main__':
    main()

which generates the following error in full,完全产生以下错误,

Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/ibm_botocore/signers.py", line 149, in sign
    auth = self.get_auth_instance(**kwargs)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/ibm_botocore/signers.py", line 222, in get_auth_instance
    signature_version=signature_version)
ibm_botocore.exceptions.UnknownSignatureVersionError: Unknown Signature Version: oauth-presign-post.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "tmp.py", line 35, in <module>
    main()
  File "tmp.py", line 30, in main
    uri = poster.generate(bucket, 'somekey')
  File "tmp.py", line 16, in generate
    return self.cos.generate_presigned_post(bucket, key, Fields, Conditions, ExpiresIn)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/ibm_botocore/signers.py", line 714, in generate_presigned_post
    expires_in=expires_in)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/ibm_botocore/signers.py", line 526, in generate_presigned_post
    'PutObject', request, region_name, 'presign-post')
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/ibm_botocore/signers.py", line 153, in sign
    signature_version=signature_version)
ibm_botocore.exceptions.UnsupportedSignatureVersionError: Signature version is not supported: oauth-presign-post

I have that working as following.我的工作如下。 When I have created the client and connected to the COS endpoint, my final call looks like this:创建客户端并连接到 COS 端点后,我的最终调用如下所示:

theURL=cos.generate_presigned_url('get_object',
                                   Params = {'Bucket': buckets[0],
                                             'Key': objects[0] 
                                            },
                                   ExpiresIn = 100)

It seems that I use that function with different parameters.看来我用不同参数的 function 。 I constructed the cos object as shown here:我构造了cos object,如下所示:

cos = ibm_boto3.client('s3',
                        config["apikey"],
                        endpoint_url='https://'+cos_host,
                        aws_access_key_id=config["cos_hmac_keys"["access_key_id"],
                        aws_secret_access_key=config["cos_hmac_keys"]["secret_access_key"])

As you can see, I passed the HMAC details.如您所见,我通过了 HMAC 详细信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 未找到 generate_presigned_post 的 BotoCore/Boto3 Stubber 操作 - BotoCore/Boto3 Stubber Operation Not Found for generate_presigned_post boto3 generate_presigned_post 未能设置自定义元标记 - boto3 generate_presigned_post failed to set custom meta tag generate_presigned_post url 由于“未提供 AWSAcesskey”而失败 - generate_presigned_post url failing due to "No AWSAcesskey was presented" 在 Django 只生成 s3 客户端 generate_presigned_post ,内容类型为 mp4 文件上传 - In Django Generate only s3 client generate_presigned_post with content type for mp4 file upload Python:如何为IBM Cloud Object Storage生成预签名URL? - Python: How do I generate presigned URLs for IBM Cloud Object Storage? ibm_boto3与Mac OS上scikit-learn的兼容性问题 - ibm_boto3 compatibility issue with scikit-learn on Mac OS boto3 eks 客户端如何生成预签名 url - boto3 eks client how to generate presigned url boto3 generate_presigned_url SignatureDoesNotMatch - boto3 generate_presigned_url SignatureDoesNotMatch AttributeError:&#39;dict&#39;对象没有属性&#39;append&#39;boto3生成预签名帖子 - AttributeError: 'dict' object has no attribute 'append' boto3 generate presigned post boto3 中 generate_presigned_url 返回值的类型是什么? - What's the type of return value from generate_presigned_url in boto3?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM