SecretID
and SecretKey
on the API Key Management page in the CAM console.SecretID
is used to identify the API caller.SecretKey
is used to encrypt the string to sign that can be verified on the server. You should keep it private and avoid disclosure.sms.tencentcloudapi.com
.# -*- coding: utf-8 -*-from tencentcloud.common import credentialfrom tencentcloud.common.exception.tencent_cloud_sdk_exception import TencentCloudSDKException# Import the client models of the corresponding product module.from tencentcloud.sms.v20210111 import sms_client, models# Import the optional configuration classesfrom tencentcloud.common.profile.client_profile import ClientProfilefrom tencentcloud.common.profile.http_profile import HttpProfiletry:# Instantiate an authentication object, the input parameters must include the Tencent Cloud account SecretId and SecretKey.# To protect key security, it is suggested to set keys in environment variables or configuration files. # Hardcoding keys into the code might lead to exposure through leaked code, posing a security vulnerability, and is not recommended.# Query SecretId, SecretKey: https://console.tencentcloud.com/cam/capi# cred = credential.Credential("secretId", "secretKey")cred = credential.Credential(os.environ.get("TENCENTCLOUD_SECRET_ID"),os.environ.get("TENCENTCLOUD_SECRET_KEY"))# (Optional) Instantiate an HTTP optionhttpProfile = HttpProfile()# If you need to specify the proxy for API access, you can initialize HttpProfile as follows# httpProfile = HttpProfile(proxy="http://username:password@proxy IP:proxy port")httpProfile.reqMethod = "POST" # POST request (POST request by default)httpProfile.reqTimeout = 10 # Request timeout period in seconds (60 seconds by default)httpProfile.endpoint = "sms.tencentcloudapi.com" # Specify the access region domain name (nearby access by default)# Optional steps:# Instantiate a client configuration object. You can specify the timeout period and other configuration itemsclientProfile = ClientProfile()clientProfile.signMethod = "TC3-HMAC-SHA256" # Specify the signature algorithmclientProfile.language = "en-US"clientProfile.httpProfile = httpProfile# Instantiate the client object of the requested product (with SMS as an example)# The second parameter is the information on the region you select in Tencent Cloud International. If you select Singapore, you should enter the string `ap-singapore`. Click https://www.tencentcloud.com/document/api/382/40466?lang=en#region-list to view the region list.client = sms_client.SmsClient(cred, "ap-singapore", clientProfile)# Instantiate a request object. You can further set the request parameters according to the API called and actual conditions# You can directly check the SDK source code to determine which attributes of `SendSmsRequest` can be set# An attribute may be of a basic type or import another data structure# We recommend you use the IDE for development where you can easily redirect to and view the documentation of each API and data structurereq = models.SendSmsRequest()# Settings of a basic parameter:# The SDK uses the pointer style to specify parameters, so even for basic parameters, you need to use pointers to assign values to them.# The SDK provides encapsulation functions for importing the pointers of basic parameters# Help link:# SMS console: https://console.tencentcloud.com/smsv2# sms helper: https://www.tencentcloud.com/document/product/382/3773# SMS application ID, which is the `SdkAppId` generated after an application is added in the [SMS console], such as 2400006666req.SmsSdkAppId = "2400006666"# SMS signature content, which should be encoded in UTF-8. You must enter an approved signature, which can be viewed in the [SMS console]req.SignName = "xxx"# SMS code number extension, which is not activated by default. If you need to activate it, please contact [SMS Helper]req.ExtendCode = ""# User session content, which can carry context information such as user-side ID and will be returned as-is by the serverreq.SessionContext = "xxx"# `senderid` for Global SMS, which is not activated by default. If you need to activate it, please contact [SMS Helper] for assistance. This parameter should be left empty for Mainland China SMSreq.SenderId = ""# Target mobile number in the E.164 standard (+[country/region code][mobile number])# Example: +60198890000, which has a + sign followed by 60 (country/region code) and then by 198890000 (mobile number). Up to 200 mobile numbers are supportedreq.PhoneNumberSet = ["+60198890000"]# Template ID. You must enter the ID of an approved template, which can be viewed in the [SMS console]req.TemplateId = "449739"# Template parameters. If there are no template parameters, leave it emptyreq.TemplateParamSet = ["666"]# Initialize the request by calling the `DescribeInstances` method on the client object. Note: the request method name corresponds to the request object# The returned `resp` is an instance of the `DescribeInstancesResponse` class which corresponds to the request objectresp = client.SendSms(req)# A string return packet in JSON format is outputtedprint(resp.to_json_string(indent=2))except TencentCloudSDKException as err:print(err)
# -*- coding: utf-8 -*-from tencentcloud.common import credentialfrom tencentcloud.common.exception.tencent_cloud_sdk_exception import TencentCloudSDKException# Import the client models of the corresponding product module.from tencentcloud.sms.v20210111 import sms_client, models# Import the optional configuration classesfrom tencentcloud.common.profile.client_profile import ClientProfilefrom tencentcloud.common.profile.http_profile import HttpProfiletry:# Instantiate an authentication object, the input parameters must include the Tencent Cloud account SecretId and SecretKey.# To protect key security, it is suggested to set keys in environment variables or configuration files. # Hardcoding keys into the code might lead to exposure through leaked code, posing a security vulnerability, and is not recommended.# Query SecretId, SecretKey: https://console.tencentcloud.com/cam/capi# cred = credential.Credential("secretId", "secretKey")cred = credential.Credential(os.environ.get("TENCENTCLOUD_SECRET_ID"),os.environ.get("TENCENTCLOUD_SECRET_KEY"))# (Optional) Instantiate an HTTP optionhttpProfile = HttpProfile()# If you need to specify the proxy for API access, you can initialize HttpProfile as follows# httpProfile = HttpProfile(proxy="http://username:password@proxy IP:proxy port")httpProfile.reqMethod = "POST" # POST request (POST request by default)httpProfile.reqTimeout = 30 # Request timeout period in seconds (60 seconds by default)httpProfile.endpoint = "sms.tencentcloudapi.com" # Specify the access region domain name (nearby access by default)# Optional steps:# Instantiate a client configuration object. You can specify the timeout period and other configuration itemsclientProfile = ClientProfile()clientProfile.signMethod = "TC3-HMAC-SHA256" # Specify the signature algorithmclientProfile.language = "en-US"clientProfile.httpProfile = httpProfile# Instantiate the client object of the requested product (with SMS as an example)# The second parameter is the information on the region you select in Tencent Cloud International. If you select Singapore, you should enter the string `ap-singapore`. Click https://www.tencentcloud.com/document/api/382/40466?lang=en#region-list to view the region list.client = sms_client.SmsClient(cred, "ap-singapore", clientProfile)# Instantiate a request object. You can further set the request parameters according to the API called and actual conditions# You can directly check the SDK source code to determine which attributes of `SendSmsRequest` can be set# An attribute may be of a basic type or import another data structure# We recommend you use the IDE for development where you can easily redirect to and view the documentation of each API and data structurereq = models.PullSmsSendStatusRequest()# Settings of a basic parameter:# The SDK uses the pointer style to specify parameters, so even for basic parameters, you need to use pointers to assign values to them.# The SDK provides encapsulation functions for importing the pointers of basic parameters# Help link:# SMS console: https://console.tencentcloud.com/smsv2# sms helper: https://www.tencentcloud.com/document/product/382/3773# SMS application ID, which is the `SdkAppId` generated after an application is added in the [SMS console], such as 2400006666req.SmsSdkAppId = "2400006666"# Maximum number of pulled entries. Maximum value: 100req.Limit = 10# Initialize the request by calling the `PullSmsSendStatus` method on the client object. Note: the request method name corresponds to the request object# The returned `resp` is an instance of the `PullSmsSendStatusResponse` class which corresponds to the request objectresp = client.PullSmsSendStatus(req)# A string return packet in JSON format is outputtedprint(resp.to_json_string(indent=2))except TencentCloudSDKException as err:print(err)
# -*- coding: utf-8 -*-from tencentcloud.common import credentialfrom tencentcloud.common.exception.tencent_cloud_sdk_exception import TencentCloudSDKException# Import the client models of the corresponding product module.from tencentcloud.sms.v20210111 import sms_client, models# Import the optional configuration classesfrom tencentcloud.common.profile.client_profile import ClientProfilefrom tencentcloud.common.profile.http_profile import HttpProfiletry:# Instantiate an authentication object, the input parameters must include the Tencent Cloud account SecretId and SecretKey.# To protect key security, it is suggested to set keys in environment variables or configuration files. # Hardcoding keys into the code might lead to exposure through leaked code, posing a security vulnerability, and is not recommended.# Query SecretId, SecretKey: https://console.tencentcloud.com/cam/capi# cred = credential.Credential("secretId", "secretKey")cred = credential.Credential(os.environ.get("TENCENTCLOUD_SECRET_ID"),os.environ.get("TENCENTCLOUD_SECRET_KEY"))# (Optional) Instantiate an HTTP optionhttpProfile = HttpProfile()# If you need to specify the proxy for API access, you can initialize HttpProfile as follows# httpProfile = HttpProfile(proxy="http://username:password@proxy IP:proxy port")httpProfile.reqMethod = "POST" # POST request (POST request by default)httpProfile.reqTimeout = 30 # Request timeout period in seconds (60 seconds by default)httpProfile.endpoint = "sms.tencentcloudapi.com" # Specify the access region domain name (nearby access by default)# Optional steps:# Instantiate a client configuration object. You can specify the timeout period and other configuration itemsclientProfile = ClientProfile()clientProfile.signMethod = "TC3-HMAC-SHA256" # Specify the signature algorithmclientProfile.language = "en-US"clientProfile.httpProfile = httpProfile# Instantiate the client object of the requested product (with SMS as an example)# The second parameter is the information on the region you select in Tencent Cloud International. If you select Singapore, you should enter the string `ap-singapore`. Click https://www.tencentcloud.com/document/api/382/40466?lang=en#region-list to view the region list.client = sms_client.SmsClient(cred, "ap-singapore", clientProfile)# Instantiate a request object. You can further set the request parameters according to the API called and actual conditions# You can directly check the SDK source code to determine which attributes of `SendSmsRequest` can be set# An attribute may be of a basic type or import another data structure# We recommend you use the IDE for development where you can easily redirect to and view the documentation of each API and data structurereq = models.SendStatusStatisticsRequest()# Settings of a basic parameter:# The SDK uses the pointer style to specify parameters, so even for basic parameters, you need to use pointers to assign values to them.# The SDK provides encapsulation functions for importing the pointers of basic parameters# Help link:# SMS console: https://console.tencentcloud.com/smsv2# sms helper: https://www.tencentcloud.com/document/product/382/3773# SMS application ID, which is the `SmsSdkAppId` generated after an application is added in the [SMS console], such as 2400006666req.SmsSdkAppId = "2400006666"# Maximum number of pulled entries. Maximum value: 100req.Limit = 10# Offset. Note: this parameter is currently fixed at 0req.Offset = 0# Start time of pull in the format of `yyyymmddhh` accurate to the hourreq.BeginTime = "2019122400"# End time of pull in the format of `yyyymmddhh` accurate to the hour# Note: `EndTime` must be after `BeginTime`req.EndTime = "2019122523"# Initialize the request by calling the `SendStatusStatistics` method on the client object. Note: the request method name corresponds to the request object# The returned `resp` is an instance of the `SendStatusStatisticsResponse` class which corresponds to the request objectresp = client.SendStatusStatistics(req)# A string return packet in JSON format is outputtedprint(resp.to_json_string(indent=2))except TencentCloudSDKException as err:print(err)
# -*- coding: utf-8 -*-from tencentcloud.common import credentialfrom tencentcloud.common.exception.tencent_cloud_sdk_exception import TencentCloudSDKException# Import the client models of the corresponding product module.from tencentcloud.sms.v20210111 import sms_client, models# Import the optional configuration classesfrom tencentcloud.common.profile.client_profile import ClientProfilefrom tencentcloud.common.profile.http_profile import HttpProfiletry:# Instantiate an authentication object, the input parameters must include the Tencent Cloud account SecretId and SecretKey.# To protect key security, it is suggested to set keys in environment variables or configuration files. # Hardcoding keys into the code might lead to exposure through leaked code, posing a security vulnerability, and is not recommended.# Query SecretId, SecretKey: https://console.tencentcloud.com/cam/capi# cred = credential.Credential("secretId", "secretKey")cred = credential.Credential(os.environ.get("TENCENTCLOUD_SECRET_ID"),os.environ.get("TENCENTCLOUD_SECRET_KEY"))# Instantiate an HTTP option (optional; skip if there are no special requirements)httpProfile = HttpProfile()# If you need to specify the proxy for API access, you can initialize HttpProfile as follows# httpProfile = HttpProfile(proxy="http://username:password@proxy IP:proxy port")httpProfile.reqMethod = "POST" # POST request (POST request by default)httpProfile.reqTimeout = 30 # Request timeout period in seconds (60 seconds by default)httpProfile.endpoint = "sms.tencentcloudapi.com" # Specify the access region domain name (nearby access by default)# Optional steps:# Instantiate a client configuration object. You can specify the timeout period and other configuration itemsclientProfile = ClientProfile()clientProfile.signMethod = "TC3-HMAC-SHA256" # Specify the signature algorithmclientProfile.language = "en-US"clientProfile.httpProfile = httpProfile# Instantiate an SMS client object# The second parameter is the information on the region you select in Tencent Cloud International. If you select Singapore, you should enter the string `ap-singapore`. Click https://www.tencentcloud.com/document/api/382/40466?lang=en#region-list to view the region list.client = sms_client.SmsClient(cred, "ap-singapore", clientProfile)# Instantiate a request object. You can further set the request parameters according to the API called and actual conditions# You can directly check the SDK source code to determine which attributes of `AddSmsTemplateRequest` can be set# An attribute may be of a basic type or import another data structure# We recommend you use the IDE for development where you can easily redirect to and view the documentation of each API and data structurereq = models.AddSmsTemplateRequest()# Settings of a basic parameter:# The SDK uses the pointer style to specify parameters, so even for basic parameters, you need to use pointers to assign values to them# The SDK provides encapsulation functions for importing the pointers of basic parameters# Help link:# SMS console: https://console.tencentcloud.com/smsv2# sms helper: https://www.tencentcloud.com/document/product/382/3773# Template namereq.TemplateName = "Tencent Cloud"# Template contentreq.TemplateContent = "Your login verification code is {1}. Please enter it within {2} minutes. If the login was not initiated by you, please ignore this message."# SMS type. 1: Marketing SMS, 2: Notification SMS, 3: OTP SMSreq.SmsType = 3# Whether it is Global SMS:# 0: Mainland China SMS# 1: Global SMSreq.International = 0# Template remarks, such as reason for application and use casereq.Remark = "xxx"# Initialize the request by calling the `AddSmsTemplate` method on the client object. Note: the request method name corresponds to the request object# The returned `resp` is an instance of the `AddSmsTemplateResponse` class which corresponds to the request objectresp = client.AddSmsTemplate(req)# A string return packet in JSON format is outputprint(resp.to_json_string(indent=2))except TencentCloudSDKException as err:print(err)
Error: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed certificate in certificate chain (_ssl.c:1056).
certifi
library needs to be used, but the SDK does not support specifying it; therefore, you can only solve this problem by installing the certificate with the sudo "/Applications/Python 3.6/Install Certificates.command"
command.sudo /Applications/Python 2.7/Install Certificates.command
.https_proxy
.
Was this page helpful?