from aliyunsdkcore import client
from aliyunsdkcms.request.v20160318 import QueryMetricListRequest
import oss2
import time
access_id = 'XXXXXXXX'
access_key = 'XXXXXXXXXXX'
bucket_name = 'XXXXXXXXXX'
endpoint = 'oss-cn-hangzhou.aliyuncs.com'
start_time = "2017-01-1 00:00:00"
end_time = "2017-01-2 00:00:00"
metric = 'InternetSend'
timestamp_start = int(time.mktime(time.strptime(start_time, "%Y-%m-%d %H:%M:%S"))) * 1000
clt = client.AcsClient('access_id','access_key','endpoint')
request = QueryMetricListRequest.QueryMetricListRequest()
request.set_accept_format('json')
request.set_Project('acs_oss')
request.set_StartTime(timestamp_start)
request.set_EndTime(end_time)
request.set_Dimensions("{instanceId:'bucket_name'}")
request.set_Period('60')
request.set_Metric(metric)
result = clt.do_action(request)
print result
报错如下:希望有好人解答
File "get_oss.py", line 25, in
result = clt.do_action(request)
File "/usr/local/lib/python2.7/site-packages/aliyunsdkcore/client.py", line 147, in do_action
raise exs.ClientException(error_code.SDK_INVALID_REGION_ID, error_msg.get_msg('SDK_INVALID_REGION_ID'))
aliyunsdkcore.acs_exception.exceptions.ClientException
看了一下java版的SDK,构建client的时候需要传入一个带regionId的ProFile,代码如下(https://help.aliyun.com/document_detail/28621.html)
IClientProfile profile = DefaultProfile.getProfile("cn-hangzhou", "", "");
IAcsClient client = new DefaultAcsClient(profile);
所以我猜python版的SDK同样也需要吧,你可以找一下python版的sdk里的client.py里是否有带profile的client,如果有的话就设置一个带regionId的profile。
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。