python调用腾讯云DNSPod API实现域名添加解析记录

腾讯云 #DNSPod

接口描述

接口请求域名: dnspod.tencentcloudapi.com 。

  • 添加记录
  • 默认接口请求频率限制:20次/秒。
    接口必须的参数
参数名称必选类型描述
DomainString你要解析的域名
RecordTypeString记录类型,通过 API 记录类型获得,大写英文,比如:A 。
RecordLineString记录线路,通过 API 记录线路获得,中文,比如:默认。
ValueString记录值,如 IP : 200.200.200.200, CNAME : cname.dnspod.com., MX : mail.dnspod.com.。

输入示例

POST / HTTP/1.1
Host: dnspod.tencentcloudapi.com
Content-Type: application/json
X-TC-Action: CreateRecord
<公共请求参数>

{
    "Domain": "dnspod.site",
    "DomainId": 62,
    "SubDomain": "bbbb",
    "RecordType": "A",
    "RecordLine": "默认",
    "RecordLineId": "0",
    "Value": "129.23.32.32",
    "MX": 0,
    "TTL": 600,
    "Weight": 10,
    "Status": "DISABLE"
}
{
  "Response": {
    "RequestId": "ab4f1426-ea15-42ea-8183-dc1b44151166",
    "RecordId": 162
  }
}

使用方法

  • 安装所需要的库
# 以腾讯源为例 
# 源地址后为所要安装的包:tencentcloud-sdk-python
pip install -i https://mirrors.tencent.com/pypi/simple/ --upgrade tencentcloud-sdk-python
  • 添加记录
import json
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.dnspod.v20210323 import dnspod_client, models
try: 
    cred = credential.Credential("SecretId", "SecretKey") #这里需要自己获取,获取方法官方有教程
    httpProfile = HttpProfile()
    httpProfile.endpoint = "dnspod.tencentcloudapi.com"

    clientProfile = ClientProfile()
    clientProfile.httpProfile = httpProfile
    client = dnspod_client.DnspodClient(cred, "", clientProfile) 

    req = models.CreateRecordRequest()
    params = {
        "Domain": "dzzxh.cn",
        "SubDomain": "zhuxiaohuan",
        "RecordType": "A",
        "RecordLine": "默认",
        "Value": "200.200.200.200"
    }
    req.from_json_string(json.dumps(params))

    resp = client.CreateRecord(req) 
    print(resp.to_json_string()) 

except TencentCloudSDKException as err: 
    print(err) 
  • 删除记录
import json
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.dnspod.v20210323 import dnspod_client, models

def deld():
    try:
        cred = credential.Credential("SecretId", "SecretKey") #这里需要自己获取,获取方法官方有教程
        httpProfile = HttpProfile()
        httpProfile.endpoint = "dnspod.tencentcloudapi.com"

        clientProfile = ClientProfile()
        clientProfile.httpProfile = httpProfile
        client = dnspod_client.DnspodClient(cred, "", clientProfile)

        req = models.DeleteRecordRequest()
        params = {
            "Domain": "dzzxh.cn",
            "RecordId": 1049597560
        }
        req.from_json_string(json.dumps(params))

        resp = client.DeleteRecord(req)
        print(resp.to_json_string())

    except TencentCloudSDKException as err:
        
        print(err)

deld()

 

请登录后发表评论

    没有回复内容