本文为您介绍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)