All Products
Search
Document Center

Alibaba Cloud SDK:Configure an HTTPS request

Last Updated:May 07, 2025

This topic describes how to configure an HTTPS request and a TLS version in Alibaba Cloud SDK V2.0 for Python.

Alibaba Cloud SDK V2.0 for Python support HTTP and HTTPS. You can select HTTP or HTTPS based on your business requirements. We recommend that you use HTTPS. If you do not specify a protocol, HTTPS is used by default. When you configure an HTTPS request, you can also specify a minimum TLS version to improve security, meet compliance requirements, and enhance compatibility.

Note

By default, Alibaba Cloud SDK V2.0 for Python supports the following TLS versions: TLSv1, TLSv1.1, TLSv1.2, and TLSv1.3.

Sample code:

import os

from alibabacloud_tea_openapi.models import Config
from Tea.core import TLSVersion

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='<ENDPOINT>',
    protocol='HTTPS'  # Send requests over HTTPS.
    tls_min_version=str(TLSVersion.TLSv1_2)  # Specify a TLS version.
)
Important

By default, if you send an API request over HTTPS, the SDK enables certificate verification to verify the validity of SSL/TLS certificates. If no certificate is configured in the development environment, an error that indicates the certificate verification fails is reported.

To ensure network communication security, we recommend that you enable certificate verification. If certificate verification must be disabled in the test environment, you can set the ignore_ssl parameter to True when you specify runtime parameters.

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',
    protocol='HTTPS'  # Send requests over HTTPS.
)
ecs_client = EcsClient(config)
runtimeOptions = RuntimeOptions(
    ignore_ssl=True  # Disable certificate verification. By default, certificate verification is enabled.
)
request = DescribeRegionsRequest()
response = ecs_client.describe_regions_with_options(request, runtimeOptions)
print(response.body)