{"record":{"id":"23be9dbc04f60fd0","repo":"XIU2/CloudflareSpeedTest","slug":"failed-to-create-dnspod-record-with-ipv4","errorCode":null,"errorMessage":"Failed to create DNSPod record with IPv4.","messagePattern":"Failed to create DNSPod record with IPv4\\.","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"script/cfst_dnspod.sh","lineNumber":73,"sourceCode":"if [ -z \"$preferred_ipv4\" ]; then\n  echo \"Failed to get the preferred IPv4 address.\"\nelse\n  echo \"BETTER IPv4: $preferred_ipv4\"\n\n  # 获取 IPv4 记录 ID\n  ipv4_record_id=$(get_record_id \"A\")\n\n  if [ -n \"$ipv4_record_id\" ]; then\n    # 更新 IPv4 记录\n    update_dns_record \"$ipv4_record_id\" \"A\" \"$preferred_ipv4\"\n    echo \"Updated DNSPod record with IPv4: $preferred_ipv4\"\n  else\n    # 创建 IPv4 记录\n    new_ipv4_record_id=$(create_dns_record \"A\" \"$preferred_ipv4\")\n    if [ -n \"$new_ipv4_record_id\" ]; then\n      echo \"Created DNSPod record with IPv4: $preferred_ipv4\"\n    else\n      echo \"Failed to create DNSPod record with IPv4.\"\n    fi\n  fi\nfi\n\n# 运行 CFST v6\n./cfst -f ipv6.txt -n 500 -o result6.csv\n\n# 读取 CSV 文件并提取优选 IPv6 地址\npreferred_ipv6=$(awk -F, 'NR==2 {print $1}' result6.csv)\n\n# 检查是否获取到了 IPv6 地址\nif [ -z \"$preferred_ipv6\" ]; then\n  echo \"Failed to get the preferred IPv6 address.\"\nelse\n  echo \"BETTER IPv6: $preferred_ipv6\"\n\n  # 获取 IPv6 记录 ID\n  ipv6_record_id=$(get_record_id \"AAAA\")","sourceCodeStart":55,"sourceCodeEnd":91,"githubUrl":"https://github.com/XIU2/CloudflareSpeedTest/blob/1da0c025d7b6f9bf0b2b0cf47a547f65430deab2/script/cfst_dnspod.sh#L55-L91","documentation":"At script/cfst_dnspod.sh:69-74, when get_record_id 'A' returned nothing the script calls create_dns_record, which POSTs to dnsapi.cn/Record.Create (line 34) and extracts .record.id via jq -r '.record.id' (line 36). The failure message at line 73 means that function echoed an empty string: curl produced no response or jq could not run/parse it, so no record id came back. The script never inspects the API status code, and jq -r prints the literal 'null' (non-empty) for a JSON null, so truly empty output usually indicates a curl/jq hard failure rather than a clean API error.","triggerScenarios":"jq not installed (command not found leaves the capture empty); curl failed (no route to dnsapi.cn, TLS error); the response is non-JSON (HTML error page, empty body); API_TOKEN/DOMAIN/SUB_DOMAIN env vars unset so login_token/domain params are empty; the record_line value 默认 mangled by a non-UTF-8 locale; the A record already exists so Record.Create returns an error status without .record.","commonSituations":"Deploying on a lean router/VPS without jq; forgetting to export API_TOKEN (its format must be 'id,token'); a domain typo so DNSPod returns an error object whose jq path yields null; running with a C locale that corrupts the UTF-8 '默认' record_line value.","solutions":["Check dependencies: command -v jq curl — install jq if missing","Run the create call by hand and inspect the raw response: curl -s -X POST -d \"login_token=$API_TOKEN&format=json&domain=$DOMAIN&sub_domain=$SUB_DOMAIN&record_type=A&record_line=默认&value=1.2.3.4\" https://dnsapi.cn/Record.Create","Verify env vars: echo \"$API_TOKEN|$DOMAIN|$SUB_DOMAIN\" must show 'id,token|your.domain|sub' (API_TOKEN is two parts joined by a comma)","If DNSPod reports the record already exists, pre-create it once in the dashboard so get_record_id finds it and the create path is never taken","Patch create_dns_record to surface errors: check .status.code == '1' and use jq -e -r '.record.id // empty'"],"exampleFix":"# script/cfst_dnspod.sh (before)\nresponse=$(curl -s -X POST -d \"...\" \"$dnspod_api_url/Record.Create\")\nrecord_id=$(echo \"$response\" | jq -r '.record.id')\n# (after)\nresponse=$(curl -s -X POST -d \"...\" \"$dnspod_api_url/Record.Create\")\nstatus=$(echo \"$response\" | jq -r '.status.code // empty' 2>/dev/null)\n[ \"$status\" = \"1\" ] || { echo \"DNSPod error: $response\" >&2; return 1; }\nrecord_id=$(echo \"$response\" | jq -r '.record.id')","handlingStrategy":"retry","validationCode":"command -v jq >/dev/null || { echo 'jq required' >&2; exit 1; }\n[ -n \"$API_TOKEN\" ] && [ -n \"$DOMAIN\" ] && [ -n \"$SUB_DOMAIN\" ] || { echo 'API_TOKEN/DOMAIN/SUB_DOMAIN unset' >&2; exit 1; }\ncurl -sf -o /dev/null https://dnsapi.cn/ || { echo 'dnsapi.cn unreachable' >&2; exit 1; }","typeGuard":null,"tryCatchPattern":"resp=$(curl -s -X POST -d \"...Record.Create params...\" https://dnsapi.cn/Record.Create)\nif ! id=$(echo \"$resp\" | jq -e -r '.record.id // empty' 2>/dev/null) || [ -z \"$id\" ]; then\n  echo \"DNSPod create failed: $resp\" >&2\nfi","preventionTips":["Install jq and verify with jq --version before relying on the script's parsers","Log and inspect the raw DNSPod response (status.code must be '1') instead of trusting an empty capture","Pre-create the A/AAAA records once in the dashboard so get_record_id finds them and the create path never runs","Keep the API token in 'id,token' form and the shell in a UTF-8 locale so the 默认 record_line survives"],"tags":["shell","bash","dnspod","api","curl","jq"],"backgroundTag":null,"analyzedSha":"1da0c025d7b6f9bf0b2b0cf47a547f65430deab2","analyzedAt":"2026-08-15T22:22:10.737Z","schemaVersion":2},"datasetVersion":"2026-08-16T03:17:38.424Z"}