jeessy2/ddns-go · error

生成签名失败: %v

Error message

生成签名失败: %v

What it means

dns/tnethk.go request() wraps a failure of t.sign(params, method) with "生成签名失败: %v" (signature generation failed). Signing runs before every Tnet.hk API call (create, modify, getRecordList), so any error building the query-string signature aborts the request locally without network I/O.

Source

Thrown at dns/tnethk.go:252

	// 6. 重新构造最终的查询字符串(包含签名)
	keys = append(keys, "Signature")
	sort.Strings(keys)
	var finalQuery []string
	for _, k := range keys {
		encodedKey := util.PercentEncode(k)
		encodedValue := util.PercentEncode(params[k])
		finalQuery = append(finalQuery, encodedKey+"="+encodedValue)
	}

	return strings.Join(finalQuery, "&"), nil
}

func (t *Tnethk) request(apiPath string, params map[string]string, method string) ([]byte, error) {
	// 生成签名
	queryString, err := t.sign(params, method)
	if err != nil {
		return nil, fmt.Errorf("生成签名失败: %v", err)
	}

	// 构造完整URL
	baseURL := "https://www.tnet.hk"
	fullURL := baseURL + apiPath + "?" + queryString

	// 创建HTTP请求
	req, err := http.NewRequest(method, fullURL, nil)
	if err != nil {
		return nil, fmt.Errorf("创建请求失败: %v", err)
	}

	// 设置请求头
	req.Header.Set("Accept", "application/json")

	// 发送请求
	client := t.httpClient
	resp, err := client.Do(req)

View on GitHub (pinned to 5874c2e666)

Solutions

  1. Check that the Tnet.hk API key and secret are set in your configuration
  2. Inspect the wrapped %v error to see the exact signing failure
  3. Re-enter credentials avoiding stray whitespace/newlines
  4. Update the library if Tnet.hk changed its signature scheme

Example fix

// before
queryString, err := t.sign(params, method)
if err != nil {
	return nil, fmt.Errorf("生成签名失败: %v", err)
}
// after (caller: validate creds before calling)
if provider.apiKey == "" || provider.secret == "" {
	return fmt.Errorf("tnethk: api key/secret must be configured")
}
Defensive patterns

Strategy: validation

Validate before calling

// before calling any tnethk operation
if tnethkAPIKey == "" || tnethkSecret == "" {
	return errors.New("tnethk: API key and secret must be configured")
}

Try / catch

if err != nil && strings.Contains(err.Error(), "生成签名失败") {
	return fmt.Errorf("tnethk signing failed — check credentials: %w", err)
}

Prevention

When it happens

Trigger: create, modify, or getRecordList calls where sign() fails — typically missing/empty API credentials or secret in the provider config causing HMAC/query construction to error.

Common situations: Unset or blank API key/secret in the DDNS config; misconfigured credential environment variables; secret containing characters that break query-string encoding; a provider API change requiring a new signature algorithm.

Related errors


AI-assisted analysis of jeessy2/ddns-go@5874c2e666 (2026-09-03). Data as JSON: /api/errors/8306d0ab4c295239. Report an issue: GitHub.