Alibaba Cloud OpenPlatform SDK for Python

raw JSON →
2.0.0 verified Fri May 01 auth: no python

The official Alibaba Cloud SDK for OpenPlatform API version 20191219, providing Python bindings to interact with Alibaba Cloud OpenPlatform services such as file upload, authorization, and more. Current version is 2.0.0, requiring Python >=3.6. Released as part of the Alibaba Cloud Python SDK ecosystem.

pip install alibabacloud-openplatform20191219
error AttributeError: module 'alibabacloud_openplatform20191219' has no attribute 'Client'
cause Importing Client from the top-level package (wrong import path).
fix
Use 'from alibabacloud_openplatform20191219.client import Client'.
error TeaException: RegionId is mandatory. Can not be empty.
cause Missing or incorrect region_id in request parameters.
fix
Ensure region_id is set in the request, e.g., AuthorizeFileUploadRequest(region_id='cn-shanghai').
breaking Version 2.0.0 changed the import structure. Previously, you could import Client directly from the top-level package; now you must import from the 'client' submodule.
fix Change 'from alibabacloud_openplatform20191219 import Client' to 'from alibabacloud_openplatform20191219.client import Client'.
gotcha Endpoint configuration is required and varies by region. Using the wrong endpoint leads to connection errors.
fix Set the endpoint to the correct regional endpoint (e.g., 'openplatform.cn-shanghai.aliyuncs.com') in the Config.
deprecated The old way of passing credentials directly in the constructor (using `access_key_id` etc.) is still supported but deprecated. Prefer using a Credential client from alibabacloud_credentials.
fix Use `from alibabacloud_credentials.client import Client as CredClient` and pass the credential client to Config.

Create a client, authorize a file upload for OSS. Requires valid Alibaba Cloud credentials set as environment variables.

import os
from alibabacloud_openplatform20191219.client import Client
from alibabacloud_openplatform20191219.models import AuthorizeFileUploadRequest
from alibabacloud_tea_openapi.models import Config

config = Config(
    access_key_id=os.environ.get('ALIBABA_CLOUD_ACCESS_KEY_ID', ''),
    access_key_secret=os.environ.get('ALIBABA_CLOUD_ACCESS_KEY_SECRET', ''),
    endpoint='openplatform.cn-shanghai.aliyuncs.com'
)
client = Client(config)
request = AuthorizeFileUploadRequest(
    product='oss',
    region_id='cn-shanghai'
)
try:
    response = client.authorize_file_upload(request)
    print(response.to_map())
except Exception as e:
    print(e)