chenhg5/cc-connect · error
weixin: %s: %w
Error message
weixin: %s: %w
What it means
The getUploadURL API call to obtain a CDN upload URL failed; uploadToWeixinCDN wraps the underlying error with the operation label. This is the WeChat/ilink API layer rejecting or failing the upload-authorization request.
Source
Thrown at platform/weixin/media_outbound.go:80
rawSize := len(plaintext)
aesKey := make([]byte, 16)
if _, err := rand.Read(aesKey); err != nil {
return nil, fmt.Errorf("weixin: %s: aes key: %w", label, err)
}
filekey := randomHex(16)
req := getUploadURLRequest{
Filekey: filekey,
MediaType: mediaType,
ToUserID: to,
Rawsize: rawSize,
Rawfilemd5: md5Hex(plaintext),
Filesize: aesECBPaddedSize(rawSize),
NoNeedThumb: true,
Aeskey: hex.EncodeToString(aesKey),
}
resp, err := p.api.getUploadURL(ctx, req)
if err != nil {
return nil, fmt.Errorf("weixin: %s: %w", label, err)
}
// 选择上传 URL 和 HTTP client
var cdnUploadURL string
var uploadClient *http.Client
if resp.UploadFullURL != "" {
// 新版 API:使用服务端返回的完整 URL
cdnUploadURL = resp.UploadFullURL
// 如果 URL 指向已知的微信国内 CDN,使用无代理 client 直连
if isWeixinCDNHost(cdnUploadURL) {
uploadClient = p.cdnHttpClient
} else {
uploadClient = p.httpClient
}
} else {
// 旧版 API:用 upload_param 构建 URL,使用配置的 httpClient
cdnUploadURL = buildCdnUploadURL(p.cdnBaseURL, resp.UploadParam, filekey)
uploadClient = p.httpClient
}View on GitHub (pinned to 4000b2338a)
Solutions
- Unwrap and inspect the wrapped error (%w) to see the root cause (auth vs network vs API ret code).
- Re-authenticate / refresh the WeChat session credentials if the error indicates expired auth.
- Check network connectivity and proxy settings from the host to the WeChat API endpoint.
- If the wrapped error is the ilink ret=-2 throttle, wait and retry later.
Defensive patterns
Strategy: try-catch
Try / catch
if err := p.SendImage(ctx, rc, img); err != nil {
var apiErr *weixin.APIError
if errors.As(err, &apiErr) { handleAPIRet(apiErr.Ret) }
else if isSendThrottled(err) { scheduleRetry(err) }
else { log.Error("upload URL fetch failed", "err", err) }
} Prevention
- Keep WeChat session credentials fresh
- Monitor connectivity to the WeChat API endpoint
- Unwrap %w errors to classify root causes
- Respect ret=-2 throttles with long backoff
When it happens
Trigger: Network failure, auth token invalid/expired, server error, or API-level ret code returned by p.api.getUploadURL during SendImage/SendFile/SendAudio.
Common situations: Expired WeChat session/credentials; ilink server rejecting the request (rate-limit, bad peer); DNS or proxy failure in the deployment environment.
Understand the failure class
Background: "API request failed": what wrapped HTTP errors from external APIs mean and how to find the real cause — this error's family across 29 libraries.
Related errors
- http %d: %s
- empty qrcode_img_content from server
- refresh QR: %w
- login confirmed but ilink_bot_id missing
- get_bot_qrcode: %w
AI-assisted analysis of chenhg5/cc-connect@4000b2338a (2026-09-06).
Data as JSON: /api/errors/782b5d18d0a07a3d.
Report an issue: GitHub.