本文為您介紹V2.0 Python SDK對於逾時的配置方式。
逾時配置方式
說明
逾時時間配置優先順序為:RuntimeOption設定->Config設定->預設,優先順序依次降低。
使用預設配置。預設連線逾時為5000毫秒,讀逾時為10000毫秒。
支援通過RuntimeOptions設定逾時時間。
import os from alibabacloud_ecs20140526.client import Client as EcsClient from alibabacloud_ecs20140526.models import DescribeRegionsRequest from alibabacloud_tea_openapi.models import Config from alibabacloud_tea_util.models import RuntimeOptions 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='ecs-cn-hangzhou.aliyuncs.com' ) ecs_client = EcsClient(config) # 對使用RuntimeOptions的請求生效 runtimeOptions = RuntimeOptions( read_timeout=10000, # 讀逾時時間 單位毫秒(ms) connect_timeout=5000 # 連線逾時 單位毫秒(ms) ) request = DescribeRegionsRequest() response = ecs_client.describe_regions_with_options(request, runtimeOptions) print(response.body)
支援通過Config設定逾時時間。
import os from alibabacloud_ecs20140526.client import Client as EcsClient from alibabacloud_ecs20140526.models import DescribeRegionsRequest from alibabacloud_tea_openapi.models import Config from alibabacloud_tea_util.models import RuntimeOptions # 逾時時間對使用此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='ecs-cn-hangzhou.aliyuncs.com', read_timeout=10000, # 讀逾時時間 單位毫秒(ms) connect_timeout=5000 # 連線逾時 單位毫秒(ms) ) ecs_client = EcsClient(config) runtimeOptions = RuntimeOptions() request = DescribeRegionsRequest() response = ecs_client.describe_regions_with_options(request, runtimeOptions) print(response.body)