Alibaba Cloud OpenAPI Utilities for Python (Tea Framework)

raw JSON →
0.2.4 verified Fri Apr 24 auth: no python maintenance

This library provides common utility functions for interacting with Alibaba Cloud's OpenAPI using the Tea Framework in Python. It includes methods for signature generation, string manipulation, and XML parsing. The current version is 0.2.4, and it is part of the Alibaba Cloud SDK ecosystem, primarily maintained on an as-needed basis for the Tea framework.

pip install alibabacloud-openapi-util
error ModuleNotFoundError: No module named 'alibabacloud_openapi_util'
cause The 'alibabacloud_openapi_util' module is not installed in the Python environment.
fix
Install the module using pip: 'pip install alibabacloud-openapi-util'.
error ImportError: cannot import name 'Client' from 'alibabacloud_openapi_util'
cause The 'Client' class is not present in the 'alibabacloud_openapi_util' module.
fix
Ensure you are importing the correct class from the appropriate module; refer to the library's documentation for the correct import statement.
error AttributeError: module 'alibabacloud_openapi_util' has no attribute 'create_signature'
cause The 'create_signature' function does not exist in the 'alibabacloud_openapi_util' module.
fix
Verify the function name and its availability in the module; consult the library's documentation for the correct function usage.
error SignatureDoesNotMatch: The request signature we calculated does not match the signature you provided. Check your key and signing method.
cause This error occurs at the Alibaba Cloud API level when the signature generated by the client (potentially using `alibabacloud-openapi-util` indirectly for signature calculation) does not match the server's calculation. Common reasons include incorrect AccessKey ID, AccessKey Secret, an outdated SDK version, or issues with the parameters included in the signature.
fix
Verify the correctness of your AccessKey ID and AccessKey Secret. Ensure the entire Alibaba Cloud SDK, including alibabacloud-openapi-util and related tea packages, are updated to their latest versions. Double-check that all required request parameters are correctly formatted and included in the signature calculation process.
error AttributeError: 'NoneType' object has no attribute 'get_access_key_id' (or similar for missing credentials) OR The input parameter "AccessKeyId" that is mandatory for processing this request is not supplied.
cause The Alibaba Cloud AccessKey ID or AccessKey Secret is not properly configured or provided to the SDK client during its initialization. This often happens if the `ALIBABA_CLOUD_ACCESS_KEY_ID` and `ALIBABA_CLOUD_ACCESS_KEY_SECRET` environment variables are not set, or if the credentials are not explicitly passed when creating the SDK client.
fix
Set the ALIBABA_CLOUD_ACCESS_KEY_ID and ALIBABA_CLOUD_ACCESS_KEY_SECRET environment variables in your system, or explicitly pass these values when initializing the Alibaba Cloud client configuration (e.g., config.accessKeyId = 'your_access_key_id').
gotcha All utility methods within the `Client` class are static methods. There is no need to instantiate `Client` (e.g., `util = Client()`). Directly call methods like `Client.get_signature(...)`.
fix Always call utility methods directly on the `Client` class, e.g., `from alibabacloud_openapi_util.client import Client; Client.some_method(...)`.
gotcha Signature generation functions (e.g., `get_signature`, `get_string_to_sign`) require specific string inputs. Ensure inputs are properly formatted strings, not bytes, and that parameters like query, headers, and body are correctly structured dictionaries or `None` as expected.
fix Refer to the method signatures in the source code or documentation to ensure correct input types and formats for dictionary keys/values. Encoding issues often arise from incorrect string handling.
gotcha This library is part of the 'Tea Framework' for Alibaba Cloud SDKs. If you are using an older or different generation of Alibaba Cloud SDKs that do not rely on the Tea Framework, the signature generation logic provided here may not be compatible or correct for your specific use case.
fix Verify that your Alibaba Cloud SDK client explicitly states compatibility with the 'Tea Framework' or utilizes `alibabacloud-openapi-util` internally. If not, consult the specific SDK's documentation for its required authentication and utility methods.
runtime status import time mem disk
3.10-alpine 0.19s 5.9MB 46.8M
3.10-slim 0.13s 6.4MB 49M
3.11-alpine 0.40s 7.3MB 50.8M
3.11-slim 0.24s 7.2MB 53M
3.12-alpine 0.51s 10.2MB 40.6M
3.12-slim 0.50s 10.2MB 43M
3.13-alpine 0.57s 10.8MB 39.8M
3.13-slim 0.47s 10.8MB 42M
3.9-alpine 0.18s 5.8MB 47.5M
3.9-slim 0.15s 5.8MB 50M

Demonstrates how to generate a string to sign and then calculate a signature using a dummy access key secret. Replace 'YOUR_ACCESS_KEY_SECRET' with an actual secret for real-world use.

from alibabacloud_openapi_util.client import Client

# Example of getting the string to sign
string_to_sign = Client.get_string_to_sign({
    'method': 'GET',
    'pathname': '/',
    'query': {'key1': 'value1', 'key2': 'value2'},
    'headers': {'User-Agent': 'Tea-Client'},
    'body': None
})
print(f"String to sign: {string_to_sign}")

# Example of getting a signature (using a dummy secret for illustration)
access_key_secret = 'YOUR_ACCESS_KEY_SECRET'
signature = Client.get_signature(access_key_secret, string_to_sign)
print(f"Signature: {signature}")