Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

腾讯云默认免费API次数100万次,默认限制200次/秒针对家庭宽带非固定IP,但是又想对外提供稳定服务的爱好者,有自己的linux虚拟机(免费的花生壳极其不稳定,故用此曲线救国法)

腾讯云默认免费API次数100万次,默认限制20次/秒(阿里云操作类似)

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

准备python环境

Code Block
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/capiapi/explorer?Product=dnspod&Version=2021-03-23&Action=ModifyRecord

Image Added

4.调整python代码内容

Code Block
titlechangedns.py
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)

需要修改的地方用包含“你自己的”标出来了,最后执行代码

...

获取APIKEY

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