The Alibaba Cloud SDK for Python supports using HTTP and HTTPS protocols to send API requests. Most Alibaba Cloud products use the HTTP protocol, whereas Resource Access Manager (RAM), Security Token Service (STS), and Key Management Service (KMS) use the HTTPS protocol.

You can specify a protocol (HTTP or HTTPS) for a request, or set a global protocol for all requests.
Note The default protocol (HTTP or HTTPS) of a service takes precedence over the global protocol. RAM, STS, and KMS can only use HTTPS.

Add OpenSSL support

The HTTPS protocol support of Alibaba Cloud SDK for Python is based on the OpenSSL support in Python. To use Alibaba Cloud SDK for Python to send HTTPS requests, add OpenSSL support for Python.

Run the python -c "import ssl" command to check whether your Python environment supports OpenSSL. If ImportError: No module named ssl does not appear, OpenSSL is already supported.

If OpenSSL is not supported, run the following command to install it:

pip install pyopenssl

Example: Set HTTP/HTTPS protocol for a request

The following code shows how to set HTTPS as the protocol for a request:

request = CreateInstanceRequest.CreateInstanceRequest()
request.set_protocol_type("https")
# Valid value: "https" or "http"

Example: Set global protocol for all requests

The following code shows how to set a global protocol for all service requests:

import aliyunsdkcore.request
aliyunsdkcore.request.set_default_protocol_type("https")
# Create a request and call client.do_action_with_exception() to send the request.