[英]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_object
和upload_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.