Python Request Example
Updated at:2025-10-27
Python demo code example for resource month bill query.
Prerequisites
pip install bce-python-sdk
Request example
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
8def query_demo(config, month, begin_time, end_time, product_type, service_type, page_no, page_size):
9 return bce_http_client.send_request(
10 config,
11 bce_v1_signer.sign,
12 [handler.parse_error, handler.parse_json],
13 http_methods.GET,
14 b"/v1/bill/resource/month",
15 None,
16 {http_headers.CONTENT_TYPE: http_content_types.JSON},
17 {
18 "month": month,
19 "beginTime": begin_time,
20 "endTime": end_time,
21 "productType": product_type,
22 "serviceType": service_type,
23 "pageNo": page_no,
24 "pageSize": page_size
25 })
26
27if __name__ == '__main__':
28 conf = BceClientConfiguration(
29 credentials = BceCredentials("Replace with user’s AccessKey", "Replace with user’s SecretKey"),
30 endpoint="billing.baidubce.com",
31 protocol=protocol.HTTP,
32 connection_timeout_in_mills=60000
33 )
34
35 res = query_demo(conf, "2021-02", "2021-02-01", "2021-02-28", "postpay", "BCC", 1, 10)
36 print(res.raw_data) # Print the HTTP response.
