edit-icon download-icon

Set HTTPS requests

Last Updated: Mar 20, 2018

Alibaba Cloud Python SDK 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.

When using Python SDK, you can specify a protocol (HTTP or HTTPS) for a specific request to use, or set a global protocol for all requests to use.

Note:

  • The default protocol of a product takes precedence over the global protocol.

  • By default, Resource Access Manager (RAM), Security Token Service (STS), and Key Management Service (KMS) use the HTTPS protocol, and cannot use HTTP protocol.

OpenSSL support

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

Run the python -c "import ssl" command to make sure the OpenSSL support is added. The OpenSSL support is added if no error is returned.

Run the following command to install OpenSSL if it is not available:

  1. pip install pyopenssl

Example: Set HTTP/HTTPS protocol for a request

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

Example: Set global protocol for all requests

  1. import aliyunsdkcore.request
  2. aliyunsdkcore.request.set_default_protocol_type("https")
  3. # Create a request and call client.do_action_with_exception() to send the request
Thank you! We've received your feedback.