All Products
Search
Document Center

Alibaba Cloud SDK:Proxy configuration

Last Updated:Oct 14, 2025

In software development, a proxy acts as an intermediary to control access to a feature or resource. Using a proxy lets you implement features such as permission checks, operation log recording, data caching, and lazy loading without changing the original code. This improves the security and performance of your program, and makes it easier to maintain and extend. This topic describes how to configure a network proxy for the V2.0 Python SDK.

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 identity authentication for access, add the username and password configured on the proxy server before the IP address. The format is: http://<user>:<password>@<IP address>:<port>

After configuring a proxy, use the no_proxy parameter to specify a list of addresses to 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 using runtime parameters (RuntimeOptions). This configuration is valid only for 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 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.