Usually we need to apply for a lot of ssl certificate , For example, the primary domain name ,cos Origin domain name ,cos Speed up the domain name and so on It's usually a little troublesome to apply one by one So if your domain name is dns Resolve in dnspod Words , You can use the following code to apply in batch
Please use this code first Child users create And authorize cloud API And SSL Certificate full permissions
Please note that To ensure the security of your account and cloud assets Please keep it carefully SecretId And SecretKey And regularly update Delete useless permissions
Go to create sub user :https://console.cloud.tencent.com/cam
Please make sure Python Version is 3.6+
see Python edition
python3 -V
Upgrade pip, Install Tencent cloud Python SDK
python -m pip install --upgrade pip pip install -i https://mirrors.tencent.com/pypi/simple/ --upgrade tencentcloud-sdk-python
import json,base64 from time import time,sleep from tencentcloud.common import credential from tencentcloud.common.profile.client_profile import ClientProfile from tencentcloud.common.profile.http_profile import HttpProfile from tencentcloud.common.exception.tencent_cloud_sdk_exception import TencentCloudSDKException from tencentcloud.ssl.v20191205 import ssl_client, models start = time() cred = credential.Credential("SecretId", "SecretKey") httpProfile = HttpProfile() httpProfile.endpoint = "ssl.tencentcloudapi.com" clientProfile = ClientProfile() clientProfile.httpProfile = httpProfile domain_name = [] while True: domain = input(' The domain name to apply for the certificate :') if domain == '': break else: domain_name.append(domain) for i in range(len(domain_name)): client = ssl_client.SslClient(cred, "", clientProfile) try: req = models.ApplyCertificateRequest() params = { "DvAuthMethod": "DNS_AUTO", "DomainName": domain_name[i] } req.from_json_string(json.dumps(params)) resp = client.ApplyCertificate(req) response = json.loads(resp.to_json_string()) print(' domain name :{0} The information has been submitted , Automatic verification after five seconds '.format(domain_name[i])) certid = response['CertificateId'] sleep(5) try: req1 = models.CompleteCertificateRequest() params1 = { "CertificateId": certid } req1.from_json_string(json.dumps(params1)) resp1 = client.CompleteCertificate(req1) response1 = json.loads(resp1.to_json_string()) print(' domain name :{0} Verify success ! Ready to download certificate '.format(domain_name[i])) try: req2 = models.DownloadCertificateRequest() params2 = { "CertificateId": certid } req2.from_json_string(json.dumps(params2)) resp2 = client.DownloadCertificate(req2) response2 = json.loads(resp2.to_json_string()) # print(response2['Content']) content = response2['Content'] with open("{0}.zip".format(domain_name[i]), "wb") as f: f.write(base64.b64decode(content)) f.close() except TencentCloudSDKException as err: print(err) except TencentCloudSDKException as err: print(err) except TencentCloudSDKException as err: print(err) end = time() print(' This code execution takes a total of :', round(end - start, 2), 's')
If you have any questions, please leave a message in the comments section , Your favorite collection and attention will be the greatest motivation for the author to create
This article was first published on 2022.1.29 18:20
This article is cloud + Community first
Reprint is prohibited without consent
This article will be published synchronously in csdn You know Bili Bili column