Python SDK

更新时间:
复制 MD 格式

This topic provides a complete example of how to use Python SDK to call the DescribeVerifyScheme operation to retrieve authentication scheme details.

Step 1: View the API documentation

Before you call the API, read the documentation for the DescribeVerifyScheme operation to understand its request parameters and required permissions. For more information, see API overview.

Step 2: Authentication

Create a RAM user and grant permissions

Important

Because your root account has high privileges, we recommend using a RAM user for API calls and routine O&M. For more information, see Overview.

  • Create a RAM user: Go to the Create User page. Specify the required information, select Permanent AccessKey for Access Configuration, then click OK. Save your AccessKey for later use.

  • Grant permissions to the RAM User: Go to the Users page. Find the RAM user that you created and click Attach Policy in the Actions column. In the Policy search box, enter AliyunDysmsFullAccess, select the policy, and then click OK.

Note
  • AliyunDypnsFullAccess: The permission to manage Phone Number Verification Service.

  • AliyunDypnsReadOnlyAccess: The permission to read the resources of Phone Number Verification Service.

  • If you need to create a custom policy, see RAM authorization.

Obtain access credentials

To prevent security risks, avoid hard-coding your AccessKey pair. Instead, retrieve it from environment variables.

Configure your AccessKey pair using environment variables. For information about how to configure environment variables, see Configure environment variables on Linux, macOS, and Windows.

Step 3: Call the API operation

This topic demonstrates how to call API operations using the Python SDK. SDKs for other programming languages follow a similar usage pattern. For more information, see the Phone Number Verification Service SDK. You can also select other calling methods as needed. For more calling methods, see Calling methods.

Prepare Python environment

Download and install Python 3. If you have Python installed, run the python --version command to check the version.

Note

Before calling the API, you must configure environment variables to allow the application to read your access credentials: VMS_AK_ENV (AccessKey ID) and VMS_SK_ENV (AccessKey Secret). For configuration methods, see Configure environment variables in Linux, macOS, and Windows.

Install dependencies

Run the following commands in sequence to install dependencies:

pip install alibabacloud_credentials
pip install alibabacloud_dypnsapi20170525
pip install alibabacloud_tea_console

Download sample code

  1. Go to DescribeVerifyScheme.

  2. On the Parameters tab, set the required parameters. In this example, set Region to China (Hangzhou).

  3. On the SSDK Sample Code tab, select Python, and then click Download Project to download the sample code package.

  4. Decompress the package and go to the alibabacloud_sample directory.

Run the code

Run the following command:

python sample.py

The following output is returned:

{
  "headers": {
    "date": "Tue, 04 Jul 2023 05:37:58 GMT",
    "content-type": "application/json;charset=utf-8",
    "content-length": "392",
    "connection": "keep-alive",
    "keep-alive": "timeout=25",
    "access-control-allow-origin": "*",
    "access-control-expose-headers": "*",
    "x-acs-request-id": "BC2766D5-CC72-5302-8091-1CEC6AF75***",
    "x-acs-trace-id": "b6dbcf003b020c6689f278520a480***",
    "etag": "3GiaUeTRBz/488MtwdjI+4g2"
  },
  "statusCode": 200,
  "body": {
    "Code": "OK",
    "Message": "OK",
    "RequestId": "BC2766D5-CC72-5302-8091-1CEC6AF756***",
    "SchemeQueryResultDTO": {
      "AppEncryptInfo": "***"
    }
  }
}