All Products
Search
Document Center

Alibaba Cloud SDK:Configure an HTTPS request

Last Updated:Jul 01, 2024

This topic describes how to configure an HTTPS request in SDK for Python V2.0.

Method

SDK for Python V2.0 allows you to specify the protocol over which API requests are sent for an SDK client. We recommend that you send API requests over HTTPS. If you do not specify the protocol, API requests are sent over HTTPS by default.

import os

from alibabacloud_tea_openapi.models import 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='<ENDPOINT>',
    protocol='HTTPS'  # Send API requests over HTTPS.
)
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 API 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)