XIU2/CloudflareSpeedTest · error

Failed to create DNSPod record with IPv4.

Error message

Failed to create DNSPod record with IPv4.

What it means

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.

Source

Thrown at script/cfst_dnspod.sh:73

if [ -z "$preferred_ipv4" ]; then
  echo "Failed to get the preferred IPv4 address."
else
  echo "BETTER IPv4: $preferred_ipv4"

  # 获取 IPv4 记录 ID
  ipv4_record_id=$(get_record_id "A")

  if [ -n "$ipv4_record_id" ]; then
    # 更新 IPv4 记录
    update_dns_record "$ipv4_record_id" "A" "$preferred_ipv4"
    echo "Updated DNSPod record with IPv4: $preferred_ipv4"
  else
    # 创建 IPv4 记录
    new_ipv4_record_id=$(create_dns_record "A" "$preferred_ipv4")
    if [ -n "$new_ipv4_record_id" ]; then
      echo "Created DNSPod record with IPv4: $preferred_ipv4"
    else
      echo "Failed to create DNSPod record with IPv4."
    fi
  fi
fi

# 运行 CFST v6
./cfst -f ipv6.txt -n 500 -o result6.csv

# 读取 CSV 文件并提取优选 IPv6 地址
preferred_ipv6=$(awk -F, 'NR==2 {print $1}' result6.csv)

# 检查是否获取到了 IPv6 地址
if [ -z "$preferred_ipv6" ]; then
  echo "Failed to get the preferred IPv6 address."
else
  echo "BETTER IPv6: $preferred_ipv6"

  # 获取 IPv6 记录 ID
  ipv6_record_id=$(get_record_id "AAAA")

View on GitHub (pinned to 1da0c025d7)

Solutions

  1. Check dependencies: command -v jq curl — install jq if missing
  2. 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
  3. 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)
  4. 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
  5. Patch create_dns_record to surface errors: check .status.code == '1' and use jq -e -r '.record.id // empty'

Example fix

# script/cfst_dnspod.sh (before)
response=$(curl -s -X POST -d "..." "$dnspod_api_url/Record.Create")
record_id=$(echo "$response" | jq -r '.record.id')
# (after)
response=$(curl -s -X POST -d "..." "$dnspod_api_url/Record.Create")
status=$(echo "$response" | jq -r '.status.code // empty' 2>/dev/null)
[ "$status" = "1" ] || { echo "DNSPod error: $response" >&2; return 1; }
record_id=$(echo "$response" | jq -r '.record.id')
Defensive patterns

Strategy: retry

Validate before calling

command -v jq >/dev/null || { echo 'jq required' >&2; exit 1; }
[ -n "$API_TOKEN" ] && [ -n "$DOMAIN" ] && [ -n "$SUB_DOMAIN" ] || { echo 'API_TOKEN/DOMAIN/SUB_DOMAIN unset' >&2; exit 1; }
curl -sf -o /dev/null https://dnsapi.cn/ || { echo 'dnsapi.cn unreachable' >&2; exit 1; }

Try / catch

resp=$(curl -s -X POST -d "...Record.Create params..." https://dnsapi.cn/Record.Create)
if ! id=$(echo "$resp" | jq -e -r '.record.id // empty' 2>/dev/null) || [ -z "$id" ]; then
  echo "DNSPod create failed: $resp" >&2
fi

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of XIU2/CloudflareSpeedTest@1da0c025d7 (2026-08-15). Data as JSON: /api/errors/23be9dbc04f60fd0. Report an issue: GitHub.