All Products
Search
Document Center

Alibaba Cloud SDK:Proxy configuration

Last Updated:Jun 16, 2026

A network proxy acts as an intermediary that controls access to resources, enabling permission checks, logging, caching, and lazy loading without modifying your code. You can configure HTTP and HTTPS proxies for the V2.0 Python SDK by using environment variables, the Config class, or RuntimeOptions.

Proxy types

The SDK supports HTTP and HTTPS proxies.

Proxy type

Description

HTTP proxy

Configure the proxy server address and port using the http_proxy parameter. The format is http://<IP address>:<port>. This applies only to HTTP requests.

HTTPS proxy

Configure the proxy server address and port using the https_proxy parameter. The format is http://<IP address>:<port>. This applies only to HTTPS requests.

Note

If the proxy server requires authentication, add the username and password before the IP address. The format is: http://<user>:<password>@<IP address>:<port>

After you configure a proxy, use the no_proxy parameter to specify addresses that bypass the proxy. Separate multiple addresses with commas. Domain names and IP addresses are supported.

Proxy configuration methods

Note

Proxy configurations are applied in the following order of precedence, from highest to lowest: RuntimeOptions, Config, and environment variables.

  • Configure the proxy using environment variables:

    Note

    Configuring no_proxy in environment variables is not supported.

    • Specify the proxy server address using the HTTP_PROXY or http_proxy environment variable.

    • Specify the proxy server address using the HTTPS_PROXY or https_proxy environment variable.

  • Configure the proxy by using runtime parameters (RuntimeOptions). This configuration applies only to requests that use these runtime parameters.

    from alibabacloud_tea_openapi.models import Config
    from alibabacloud_tea_util.models import RuntimeOptions
    
    config = Config(
        protocol='https',  # The request protocol is related to the HTTP proxy configuration parameters. httpsProxy is valid only for the HTTPS protocol, and httpProxy is valid only for the HTTP protocol.
    )
    
    # Configure the proxy in RuntimeOptions
    runtimeOptions = RuntimeOptions(
        http_proxy='http://127.0.0.1:9898',
        https_proxy='http://127.0.0.1:8989',
        no_proxy='127.0.0.1,localdomain.com'
    )
    
    
  • Configure the proxy by using the Config class during client initialization. This configuration applies to all requests.

    from alibabacloud_tea_openapi.models import Config
    
    config = Config(
        protocol='https',  # The request protocol is related to the HTTP proxy configuration parameters. httpsProxy is valid only for the HTTPS protocol, and httpProxy is valid only for the HTTP protocol.
        # Proxy configuration
        http_proxy='http://127.0.0.1:9898',
        https_proxy='http://127.0.0.1:8989',
        no_proxy='127.0.0.1,localdomain.com'
    )
    

References

For a tutorial about proxy configuration, see HTTP proxy configuration tutorial.