|
| 1 | +English | [中文](README.md) |
| 2 | + |
| 3 | +# Volcengine SDK for Python |
| 4 | +## ⚠️ Known Issue (Historical Versions) |
| 5 | + |
| 6 | +In some historical versions of **volcengine-python-sdk** (**4.0.1 – 4.0.42**, inclusive), the SDK’s built-in retry mechanism has a defect. |
| 7 | + |
| 8 | +When a request encounters an exception (such as network instability or API errors), the SDK may trigger its retry logic internally; however, due to this defect, the retry does not take effect as expected. As a result, the client may still experience the exception from the initial request, and the retry mechanism cannot effectively improve request success rates. |
| 9 | + |
| 10 | +### Affected Versions |
| 11 | + |
| 12 | +- **SDK**: volcengine-python-sdk |
| 13 | +- **Versions**: 4.0.1 – 4.0.42 (inclusive) |
| 14 | + |
| 15 | +### Impact |
| 16 | + |
| 17 | +For applications that rely on the SDK’s retry mechanism to handle transient failures or network instability: |
| 18 | + |
| 19 | +- Actual request availability may be lower than expected |
| 20 | +- Retry configurations may not function as intended |
| 21 | + |
| 22 | +### Resolution and Recommendation |
| 23 | + |
| 24 | +This issue has been fixed in **version 4.0.43 and above**. |
| 25 | +**We strongly recommend all users upgrade to volcengine-python-sdk ≥ 4.0.43** to ensure the retry mechanism functions correctly in exception scenarios. |
| 26 | + |
| 27 | +## Breaking Change Notice |
| 28 | + |
| 29 | +Breaking change notice for Volcengine SDK for Python. |
| 30 | + |
| 31 | +Affected versions: `3.0.1` and later |
| 32 | + |
| 33 | +Change description: |
| 34 | + |
| 35 | +To address installation failures on Windows caused by excessively long package paths, starting from `3.0.1` we shortened some overly long API model filenames under the `transitrouter` service. If you depended on those full model filenames, this change is not backward compatible. Use the shortened model name as follows: |
| 36 | + |
| 37 | +```python |
| 38 | +from volcenginesdktransitrouter import TransitRouterBandwidthPackageForDescribeTransitRouterBandwidthPackagesOutput |
| 39 | + |
| 40 | +var = TransitRouterBandwidthPackageForDescribeTransitRouterBandwidthPackagesOutput() |
| 41 | +``` |
| 42 | + |
| 43 | +Impacted service and APIs: |
| 44 | + |
| 45 | +Service: `transitrouter` |
| 46 | + |
| 47 | +Version: `2020-04-01` |
| 48 | + |
| 49 | +APIs: |
| 50 | + |
| 51 | +- DescribeTransitRouterBandwidthPackages |
| 52 | +- DescribeTransitRouterRoutePolicyTables |
| 53 | +- DescribeTransitRouterRoutePolicyEntries |
| 54 | +- DescribeTransitRouterForwardPolicyTables |
| 55 | +- DescribeTransitRouterBandwidthPackagesBilling |
| 56 | +- DescribeTransitRouterDirectConnectGatewayAttachments |
| 57 | +- DescribeTransitRouterRouteTableAssociations |
| 58 | +- DescribeTransitRouterRouteTablePropagations |
| 59 | +- DescribeTransitRouterTrafficQosQueueEntries |
| 60 | +- DescribeTransitRouterTrafficQosQueuePolicies |
| 61 | +- DescribeTransitRouterTrafficQosMarkingEntries |
| 62 | +- DescribeTransitRouterTrafficQosMarkingPolicies |
| 63 | + |
| 64 | +-------- |
| 65 | + |
| 66 | +Affected versions: `2.0.1` and later |
| 67 | + |
| 68 | +Change description: |
| 69 | + |
| 70 | +Starting from `2.0.1`, the default request protocol changes from **HTTP** to **HTTPS**. After upgrading, ensure you test for compatibility risks. If you must continue using HTTP (not recommended), set `scheme` to `http`: |
| 71 | + |
| 72 | +```python |
| 73 | +import volcenginesdkcore |
| 74 | + |
| 75 | +configuration = volcenginesdkcore.Configuration() |
| 76 | +configuration.scheme = 'http' |
| 77 | +``` |
| 78 | + |
| 79 | +## Table of Contents |
| 80 | + |
| 81 | +* Requirements |
| 82 | +* Install |
| 83 | +* Usage |
| 84 | +* FAQ |
| 85 | + |
| 86 | +### Requirements |
| 87 | + |
| 88 | +* Python version **>= 2.7**. |
| 89 | +* On Windows, installation may fail due to maximum path length limitations. Configure it as follows: |
| 90 | + |
| 91 | +``` |
| 92 | +1. Press Win+R, type regedit to open Registry Editor. |
| 93 | +2. Set LongPathsEnabled to 1 at: |
| 94 | + HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\FileSystem |
| 95 | +``` |
| 96 | + |
| 97 | +### Install |
| 98 | + |
| 99 | +Install via pip: |
| 100 | + |
| 101 | +```sh |
| 102 | +pip install volcengine-python-sdk |
| 103 | +``` |
| 104 | + |
| 105 | +Install via [Setuptools](http://pypi.python.org/pypi/setuptools): |
| 106 | + |
| 107 | +```sh |
| 108 | +python setup.py install --user |
| 109 | +``` |
| 110 | + |
| 111 | +(Or `sudo python setup.py install` to install for all users) |
| 112 | + |
| 113 | +### Configuration Usage |
| 114 | + |
| 115 | +Step 1: initialize and configure global defaults |
| 116 | + |
| 117 | +```python |
| 118 | +configuration = volcenginesdkcore.Configuration() |
| 119 | +configuration.client_side_validation = True # enable client-side validation |
| 120 | +configuration.schema = "http" # https or http |
| 121 | +configuration.debug = False |
| 122 | +configuration.logger_file = "sdk.log" |
| 123 | + |
| 124 | +volcenginesdkcore.Configuration.set_default(configuration) |
| 125 | +``` |
| 126 | + |
| 127 | +Step 2: get the client |
| 128 | + |
| 129 | +```python |
| 130 | +def get_client(ak, sk, region): |
| 131 | + configuration = volcenginesdkcore.Configuration() |
| 132 | + configuration.ak = ak |
| 133 | + configuration.sk = sk |
| 134 | + configuration.region = region |
| 135 | + client = volcenginesdkautoscaling.AUTOSCALINGApi(volcenginesdkcore.ApiClient(configuration)) |
| 136 | + return client |
| 137 | +``` |
| 138 | + |
| 139 | +### Endpoint Configuration |
| 140 | + |
| 141 | +To customize the endpoint: |
| 142 | + |
| 143 | +```python |
| 144 | +configuration = volcenginesdkcore.Configuration() |
| 145 | +configuration.host = 'ecs.cn-beijing-autodriving.volcengineapi.com' |
| 146 | +``` |
| 147 | + |
| 148 | +Standard endpoint rules: |
| 149 | + |
| 150 | +| Regional Service | Global Service | |
| 151 | +|---|---| |
| 152 | +| `{service}.{region}.volcengineapi.com` <br> e.g. `ecs.cn-beijing-autodriving.volcengineapi.com` | `{service}.volcengineapi.com` <br> e.g. `iam.volcengineapi.com` | |
| 153 | + |
| 154 | +Note: |
| 155 | + |
| 156 | +- If the service name contains `_`, it should be converted to `-` in the endpoint. Use lowercase for all characters. |
| 157 | + |
| 158 | +### SDK Example |
| 159 | + |
| 160 | +```python |
| 161 | +from __future__ import print_function |
| 162 | +import volcenginesdkecs |
| 163 | +import volcenginesdkcore |
| 164 | +from pprint import pprint |
| 165 | +from volcenginesdkcore.rest import ApiException |
| 166 | + |
| 167 | +if __name__ == '__main__': |
| 168 | + configuration = volcenginesdkcore.Configuration() |
| 169 | + configuration.ak = "Your AK" |
| 170 | + configuration.sk = "Your SK" |
| 171 | + configuration.region = "cn-beijing" |
| 172 | + configuration.client_side_validation = True |
| 173 | + volcenginesdkcore.Configuration.set_default(configuration) |
| 174 | + |
| 175 | + api_instance = volcenginesdkecs.ECSApi() |
| 176 | + |
| 177 | + try: |
| 178 | + resp = api_instance.run_instances( |
| 179 | + volcenginesdkecs.RunInstancesRequest( |
| 180 | + instance_name="insname", |
| 181 | + instance_type="ecs.g1.large", |
| 182 | + zone_id="cn-beijing-a", |
| 183 | + network_interfaces=[volcenginesdkecs.NetworkInterfaceForRunInstancesInput( |
| 184 | + subnet_id="subnet-2d68bh73d858ozfekrm8fj", |
| 185 | + security_group_ids=["sg-2b3dq7v0ha0w2dx0eg0nhljv"], |
| 186 | + )], |
| 187 | + image_id="image-ybvz29l3da4ox5h0m9", |
| 188 | + volumes=[volcenginesdkecs.VolumeForRunInstancesInput( |
| 189 | + volume_type="ESSD", |
| 190 | + size=40, |
| 191 | + )], |
| 192 | + key_pair_name="vtable", |
| 193 | + instance_charge_type="PostPaid" |
| 194 | + )) |
| 195 | + pprint(resp) |
| 196 | + except ApiException as e: |
| 197 | + print("Exception when calling ECSApi->run_instances: %s\n" % e) |
| 198 | +``` |
| 199 | + |
| 200 | +For more examples, see: [SDK Integration Guide](./SDK_Integration.md) |
| 201 | + |
| 202 | +### FAQ |
| 203 | + |
| 204 | +For common issues when using the SDK, see [FAQ](FAQ.EN.md). |
| 205 | + |
0 commit comments