Back to snippets
alibabacloud_openapi_util_dict_to_string_map_and_canonical_query.py
pythonThis quickstart demonstrates how to use the utility to convert
Agent Votes
1
0
100% positive
alibabacloud_openapi_util_dict_to_string_map_and_canonical_query.py
1import os
2from alibabacloud_openapi_util.client import Client
3
4
5def main():
6 # Example 1: Convert a map/dict to a map of strings
7 # This is often used for normalizing headers or query parameters
8 input_dict = {
9 "key1": "value1",
10 "key2": 123,
11 "key3": True
12 }
13 string_map = Client.convert_key(input_dict)
14 print(f"Converted Map: {string_map}")
15
16 # Example 2: Get a signed string (Commonly used in Aliyun SDK internal signature logic)
17 # This mimics the preparation of a string for a canonical request
18 query = {
19 "RegionId": "cn-hangzhou",
20 "Action": "DescribeInstances"
21 }
22 canonical_query_string = Client.get_canonical_query_string(query)
23 print(f"Canonical Query String: {canonical_query_string}")
24
25 # Example 3: String manipulation helpers
26 content = "test_content"
27 is_empty = Client.is_empty(content)
28 print(f"Is content empty? {is_empty}")
29
30
31if __name__ == '__main__':
32 main()