This topic describes how to configure a proxy in SDK for Python V1.0.
Methods
Configure a proxy by using an AcsClient instance.
import os from aliyunsdkcore.client import AcsClient from aliyunsdkecs.request.v20140526.DescribeRegionsRequest import DescribeRegionsRequest # Initialize an SDK client. client = AcsClient( ak=os.environ.get('ALIBABA_CLOUD_ACCESS_KEY_ID'), # Obtain the AccessKey ID of the Resource Access Management (RAM) user from an environment variable. secret=os.environ.get('ALIBABA_CLOUD_ACCESS_KEY_SECRET'), # Obtain the AccessKey secret of the RAM user from an environment variable. region_id='cn-beijing', # The region ID. # Configure the proxy. proxy={'http': 'http://127.0.0.1:9898'} # proxy={'https': 'http://<user>:<password>@127.0.0.1:8989'} ) # Create an API request and configure parameters. request = DescribeRegionsRequest() #Send the request. response = client.do_action_with_exception(request) print(str(response, encoding='utf-8'))Configure a proxy by using one of the following environment variables:
HTTP_PROXY or http_proxy. Example of a valid value: http://127.0.0.1:9898.
HTTPS_PROXY or https_proxy. Set the environment variable in the following format: http://<user>:<password>@127.0.0.1:8989.
Note
The priority levels of the methods that are used to configure a proxy are listed in descending order: use an AcsClient instance and use an environment variable.