Python请求示例
更新时间:2021-03-29
资源月账单查询Python demo代码示例
前置条件
pip install bce-python-sdk
请求示例
Plain Text
1from baidubce.auth import bce_v1_signer
2from baidubce import protocol
3from baidubce.auth.bce_credentials import BceCredentials
4from baidubce.bce_client_configuration import BceClientConfiguration
5from baidubce.http import bce_http_client, http_content_types, http_headers
6from baidubce.http import handler
7from baidubce.http import http_methods
8
9def query_demo(config, month, begin_time, end_time, product_type, service_type, page_no, page_size):
10 return bce_http_client.send_request(
11 config,
12 bce_v1_signer.sign,
13 [handler.parse_error, handler.parse_json],
14 http_methods.GET,
15 b"/v1/bill/resource/month",
16 None,
17 {http_headers.CONTENT_TYPE: http_content_types.JSON},
18 {
19 "month": month,
20 "beginTime": begin_time,
21 "endTime": end_time,
22 "productType": product_type,
23 "serviceType": service_type,
24 "pageNo": page_no,
25 "pageSize": page_size
26 })
27
28if __name__ == '__main__':
29 conf = BceClientConfiguration(
30 credentials=BceCredentials("替换成用户的AccessKey", "替换成用户的SecretKey"),
31 endpoint="billing.baidubce.com",
32 protocol=protocol.HTTP,
33 connection_timeout_in_mills=60000
34 )
35
36 res = query_demo(conf, "2021-02", "2021-02-01", "2021-02-28", "postpay", "BCC", 1, 10)
37 print(res.raw_data) # 打印出http响应