-
Notifications
You must be signed in to change notification settings - Fork 34
Closed
Description
这边使用alibabacloud_oss20190517 这个模块去给oss policy 做更新操作的时候出现报错:RuntimeError: Failed to parse the value as json format, Value: "".
请问 oss_20190517_models.PutBucketPolicyRequest 这个方法应该给什么参数才能正常完成oss policy更新请求,测试代码请参考下面
import os
import sys
from typing import List
from alibabacloud_tea_openapi import models as open_api_models
from alibabacloud_tea_util import models as util_models
from aliyun_credentials import AliyunCredentials
from alibabacloud_oss20190517.client import Client as OssManagementClient
from alibabacloud_oss20190517 import models as oss_20190517_models
import json
region = "cn-shanghai"
subscription = "sandbox"
access_key_id, access_key_secret, security_token = AliyunCredentials.default_credentials(region, subscription )
# rds_endpoint = "rds.aliyuncs.com"
runtime = util_models.RuntimeOptions()
config = open_api_models.Config(
# 必填,请确保代码运行环境设置了环境变量 ALIBABA_CLOUD_ACCESS_KEY_ID。,
access_key_id=access_key_id,
# 必填,请确保代码运行环境设置了环境变量 ALIBABA_CLOUD_ACCESS_KEY_SECRET。,
access_key_secret=access_key_secret,
security_token=security_token
)
config.endpoint = f'oss-cn-shanghai.aliyuncs.com'
oss_client = OssManagementClient(config)
policy_json={'Version': '1', 'Statement': [{'Effect': 'Allow', 'Action': ['oss:GetObject'], 'Principal': ['xxxxxx'], 'Resource': ['acs:oss:*:xxxxxxx:xxxxxxxx'], 'Condition': {'IpAddress': {'acs:SourceIp': ['1.1.1.1','2.2.2.2']}}}]}
put_bucket_policy_request = oss_20190517_models.PutBucketPolicyRequest(policy=json.dumps(policy_json))
updateres = oss_client.put_bucket_policy(bucket="xxxxbucket",request=put_bucket_policy_request)
print(updateres)
Metadata
Metadata
Assignees
Labels
No labels