开发者社区> 问答> 正文

python 获取OSS 流量 有报错。

vvvvvvvvsmile 2017-01-13 14:37:48 3072

-- coding:utf-8 --

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

分享到
取消 提交回答
全部回答(1)
  • 名字不能长
    2019-07-17 20:42:29

    看了一下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。

    0 0