Skip to content

Commit d5793f8

Browse files
OrisdaddyAxiosLeo
authored andcommitted
Improve document
1 parent 346ef07 commit d5793f8

8 files changed

+191
-0
lines changed

README.md

+3
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ This document introduces how to obtain and call Alibaba Cloud Python SDK.
3232
- [Proxy Configurations](./docs/4-Proxy-EN.md)
3333
- [Log](./docs/5-Log-EN.md)
3434
- [Endpoint](./docs/6-Endpoint-EN.md)
35+
- [Https](./docs/7-Https-EN.md)
36+
- [Debug](./docs/8-Debug-EN.md)
37+
- [Exception](./docs/9-Exception-EN.md)
3538

3639
## Prerequisites
3740

README_zh.md

+4
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@
2929
- [代理配置](./docs/4-Proxy-CN.md)
3030
- [日志](./docs/5-Log-CN.md)
3131
- [域名](./docs/6-Endpoint-CN.md)
32+
- [Https配置](./docs/7-Https-CN.md)
33+
- [调试](./docs/8-Debug-CN.md)
34+
- [异常](./docs/9-Exception-CN.md)
35+
3236

3337
## 环境准备
3438

docs/7-Https-CN.md

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# HTTPS配置
2+
1. 忽略证书
3+
4+
```python
5+
from aliyunsdkcore.client import AcsClient
6+
7+
client = AcsClient(
8+
'<access_key_id>', # AccessKey ID
9+
'<access_secret>', # Access Key Secret
10+
'<region_id>', # 地域ID
11+
verify=False # 忽略对 SSL 证书的验证
12+
)
13+
```
14+
15+
2. 指定CA证书文件
16+
```python
17+
from aliyunsdkcore.client import AcsClient
18+
19+
client = AcsClient(
20+
'<access_key_id>', # AccessKey ID
21+
'<access_secret>', # Access Key Secret
22+
'<region_id>', # 地域ID
23+
verify='./cacert.pem' # 证书路径
24+
)
25+
```

docs/7-Https-EN.md

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# HTTPS Configurations
2+
1. Ignore certificate
3+
4+
```python
5+
from aliyunsdkcore.client import AcsClient
6+
7+
client = AcsClient(
8+
'<access_key_id>', # AccessKey ID
9+
'<access_secret>', # Access Key Secret
10+
'<region_id>', # Region ID
11+
verify=False # Ignore verifying the SSL certificate
12+
)
13+
```
14+
15+
2. Specify CA certificate
16+
```python
17+
from aliyunsdkcore.client import AcsClient
18+
19+
client = AcsClient(
20+
'<access_key_id>', # AccessKey ID
21+
'<access_secret>', # Access Key Secret
22+
'<region_id>', # Region ID
23+
verify='./cacert.pem' # Path with certificates of trusted CA
24+
)
25+
```

docs/8-Debug-CN.md

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# 调试
2+
如果存在环境变量 `DEBUG=sdk` ,所有请求将启用调试输出。
3+
4+
```bash
5+
# 请求信息
6+
> POST /?PageSize=1&Version=2014-05-26&Action=DescribeInstances&Format=JSON&RegionId=cn-hangzhou&Timestamp=2021-02-03T02%3A12%3A32Z&SignatureMethod=HMAC-SHA1&SignatureType=&SignatureVersion=1.0&SignatureNonce=cd8f5036-4818-5775-8555-00579843f220&Signature=z7X%2B0bL9wWZ1WeHzksamtOoanbo%3D HTTP/1.1
7+
> Host : ecs-cn-hangzhou.aliyuncs.com
8+
> User-Agent : AlibabaCloud (Darwin 19.5.0;x86_64) Python/3.7.6 Core/2.13.30 python-requests/2.18.3
9+
> Accept-Encoding : gzip, deflate
10+
> Accept : */*
11+
> Connection : keep-alive
12+
> x-acs-action : DescribeInstances
13+
> x-acs-version : 2014-05-26
14+
> x-sdk-invoke-type : normal
15+
> x-sdk-client : python/2.0.0
16+
> Content-Length : 0
17+
18+
# 响应信息
19+
< HTTP/1.1 200 OK
20+
< Date : Wed, 03 Feb 2021 02:12:32 GMT
21+
< Content-Type : application/json;charset=utf-8
22+
< Transfer-Encoding : chunked
23+
< Connection : keep-alive
24+
< Vary : Accept-Encoding
25+
< Access-Control-Allow-Origin : *
26+
< Access-Control-Allow-Methods : POST, GET, OPTIONS
27+
< Access-Control-Allow-Headers : X-Requested-With, X-Sequence, _aop_secret, _aop_signature
28+
< Access-Control-Max-Age : 172800
29+
< Content-Encoding : gzip
30+
```
31+

docs/8-Debug-EN.md

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Debugging
2+
If there is an environment variable `DEBUG=sdk`, all requests will enable debug mode.
3+
4+
```bash
5+
# request
6+
> POST /?PageSize=1&Version=2014-05-26&Action=DescribeInstances&Format=JSON&RegionId=cn-hangzhou&Timestamp=2021-02-03T02%3A12%3A32Z&SignatureMethod=HMAC-SHA1&SignatureType=&SignatureVersion=1.0&SignatureNonce=cd8f5036-4818-5775-8555-00579843f220&Signature=z7X%2B0bL9wWZ1WeHzksamtOoanbo%3D HTTP/1.1
7+
> Host : ecs-cn-hangzhou.aliyuncs.com
8+
> User-Agent : AlibabaCloud (Darwin 19.5.0;x86_64) Python/3.7.6 Core/2.13.30 python-requests/2.18.3
9+
> Accept-Encoding : gzip, deflate
10+
> Accept : */*
11+
> Connection : keep-alive
12+
> x-acs-action : DescribeInstances
13+
> x-acs-version : 2014-05-26
14+
> x-sdk-invoke-type : normal
15+
> x-sdk-client : python/2.0.0
16+
> Content-Length : 0
17+
18+
# response
19+
< HTTP/1.1 200 OK
20+
< Date : Wed, 03 Feb 2021 02:12:32 GMT
21+
< Content-Type : application/json;charset=utf-8
22+
< Transfer-Encoding : chunked
23+
< Connection : keep-alive
24+
< Vary : Accept-Encoding
25+
< Access-Control-Allow-Origin : *
26+
< Access-Control-Allow-Methods : POST, GET, OPTIONS
27+
< Access-Control-Allow-Headers : X-Requested-With, X-Sequence, _aop_secret, _aop_signature
28+
< Access-Control-Max-Age : 172800
29+
< Content-Encoding : gzip
30+
```
31+

docs/9-Exception-CN.md

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# 异常
2+
3+
## 异常处理
4+
使用 `try...except...` 处理服务器异常和客户端异常。
5+
```python
6+
#!/usr/bin/env python
7+
#coding=utf-8
8+
9+
from aliyunsdkcore.client import AcsClient
10+
from aliyunsdkcore.acs_exception.exceptions import ClientException
11+
from aliyunsdkcore.acs_exception.exceptions import ServerException
12+
from aliyunsdkecs.request.v20140526.DescribeImagesRequest import DescribeImagesRequest
13+
14+
client = AcsClient('<accessKeyId>', '<accessSecret>', 'cn-hangzhou')
15+
16+
request = DescribeImagesRequest()
17+
request.set_ImageOwnerAlias("system")
18+
try:
19+
response = client.do_action_with_exception(request)
20+
print(response)
21+
except ClientException as e:
22+
# 客户端异常
23+
print(e)
24+
except ServerException as e:
25+
# 服务端异常
26+
print(e)
27+
```
28+
29+
## 解决异常
30+
31+
| 错误码 | 异常信息 | 解决办法 |
32+
|----------------------|----------------------|------------------|
33+
| SDK.InvalidRegionID| can not find endpoint to access | 旧SDK版本的报错,请将`aliyun-python-sdk-core`升级到最新版本,或检查是否安装了正确的`aliyun-python-sdk-core` |
34+
| SDK.EndpointResolvingError| No such region <region-id>. Please check your region ID. |检查Region ID,参见地域列表。|
35+
| SDK.EndpointResolvingError| No endpoint for product <product-id>. |1,将`aliyun-python-sdk-core`,以及产品SDK(例如`aliyun-python-sdk-ecs`)升级到最新版本。<br />2,设置Endpoint来发送请求。|
36+

docs/9-Exception-EN.md

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# 1Exceptions
2+
3+
## Exception handlers
4+
Use `try...except...` statement to handle server exceptions and client exceptions.
5+
```python
6+
#!/usr/bin/env python
7+
#coding=utf-8
8+
9+
from aliyunsdkcore.client import AcsClient
10+
from aliyunsdkcore.acs_exception.exceptions import ClientException
11+
from aliyunsdkcore.acs_exception.exceptions import ServerException
12+
from aliyunsdkecs.request.v20140526.DescribeImagesRequest import DescribeImagesRequest
13+
14+
client = AcsClient('<accessKeyId>', '<accessSecret>', 'cn-hangzhou')
15+
16+
request = DescribeImagesRequest()
17+
request.set_ImageOwnerAlias("system")
18+
try:
19+
response = client.do_action_with_exception(request)
20+
print(response)
21+
except ClientException as e:
22+
# Client Exception
23+
print(e)
24+
except ServerException as e:
25+
# Server Exception
26+
print(e)
27+
```
28+
29+
## Resolve exception
30+
31+
| Error Code | Error Message | Solutions |
32+
|----------------------|----------------------|------------------|
33+
| SDK.InvalidRegionID| can not find endpoint to access | 1.Upgrade `aliyun-python-sdk-core` to the latest version.<br />2.Check whether the correct "aliyun-python-sdk-core" module is installed. |
34+
| SDK.EndpointResolvingError| No such region <region-id>. Please check your region ID. |Check the Region ID, see the list of regions.|
35+
| SDK.EndpointResolvingError| No endpoint for product <product-id>. |1.Upgrade `aliyun-python-sdk-core` and product SDK (such as `aliyun-python-sdk-ecs`) to the latest version.<br />2.Set Endpoint to send request.|
36+

0 commit comments

Comments
 (0)