You are viewing an old version of this page. View the current version.

Compare with Current View Page History

Version 1 Next »

准备python环境


yum install python3
tee /etc/pip.conf << EOF
[global]
index-url = http://mirrors.aliyun.com/pypi/simple/
[install]
trusted-host=mirrors.aliyun.com
EOF

pip3 install tencentcloud-sdk-python-dnspod


访问腾讯云官网获取域名相关ID信息

1.获取域名ID在右边的输出结果中,名为DomainId的字段
https://console.cloud.tencent.com.cn/api/explorer?Product=dnspod&Version=2021-03-23&Action=DescribeDomainList

2.获取域名解析记录ID在右边的输出结果中,找到你想要修改的记录值名为RecordId的字段
https://console.cloud.tencent.com.cn/api/explorer?Product=dnspod&Version=2021-03-23&Action=DescribeRecordList

3.获取APIKEY

https://console.cloud.tencent.com.cn/cam/capi

4.调整python代码内容

import json
import types
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.ModifyRecordRequest()
    params = {
    "Domain": "你自己的域名",
    "DomainId": 你自己的DomainId,
    "SubDomain": "你自己的记录名",
    "RecordType": "A",
    "RecordLine": "默认",
    "RecordLineId": "0",
    "Value": "你自己的服务器IP,
    "MX": 0,
    "TTL": 600,
    "Weight": 10,
    "Status": "DISABLE",
    "RecordId": 你自己的RecordId
    }
    req.from_json_string(json.dumps(params))

    # 返回的resp是一个ModifyRecordResponse的实例,与请求对象对应
    resp = client.ModifyRecord(req)
    # 输出json格式的字符串回包
    print(resp.to_json_string())

except TencentCloudSDKException as err:
    print(err)

需要修改的地方用包含你自己的标出来了

  • No labels