开发者社区> 问答> 正文

python 获取OSS 流量 有报错。

-- 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

展开
收起
vvvvvvvvsmile 2017-01-13 14:37:48 6464 0
1 条回答
写回答
取消 提交回答
  • 看了一下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。

    2019-07-17 20:42:29
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
From Python Scikit-Learn to Sc 立即下载
Data Pre-Processing in Python: 立即下载
双剑合璧-Python和大数据计算平台的结合 立即下载