chenhg5/cc-connect · error
qq: HTTP %s invalid response
Error message
qq: HTTP %s invalid response
What it means
callHTTPAPI returns this when the QQ HTTP API response body cannot be unmarshaled into the expected JSON envelope (status/retcode/data/message). It indicates the endpoint responded with something other than the OneBot JSON protocol — the shape of the response is wrong, not the transport.
Source
Thrown at platform/qq/qq.go:626
resp, err := client.Do(req)
if err != nil {
return nil, fmt.Errorf("qq: HTTP %s failed: %w", action, err)
}
defer resp.Body.Close()
raw, err := io.ReadAll(resp.Body)
if err != nil {
return nil, fmt.Errorf("qq: HTTP %s read body: %w", action, err)
}
var apiResp struct {
Status string `json:"status"`
RetCode int `json:"retcode"`
Data json.RawMessage `json:"data"`
Message string `json:"message"`
}
if json.Unmarshal(raw, &apiResp) != nil {
return nil, fmt.Errorf("qq: HTTP %s invalid response", action)
}
if apiResp.RetCode != 0 {
return nil, fmt.Errorf("qq: HTTP %s failed (retcode=%d, msg=%s)", action, apiResp.RetCode, apiResp.Message)
}
var result map[string]any
_ = json.Unmarshal(apiResp.Data, &result)
return result, nil
}
// ── Helpers ─────────────────────────────────────────────────────
type replyContext struct {
messageType string // "private" or "group"
userID int64
groupID int64
messageID int32
}
View on GitHub (pinned to 4000b2338a)
Solutions
- Log the raw response body on failure to see what the server actually returned.
- Verify the configured endpoint URL is the OneBot HTTP API (e.g. http://127.0.0.1:5700), not a web dashboard.
- Confirm the QQ server implementation (go-cqhttp/Lagrange etc.) speaks the expected OneBot v11 JSON format.
- Check for a reverse proxy intercepting the request with HTML error pages.
Example fix
// before
if json.Unmarshal(raw, &apiResp) != nil {
return nil, fmt.Errorf("qq: HTTP %s invalid response", action)
}
// after
if err := json.Unmarshal(raw, &apiResp); err != nil {
return nil, fmt.Errorf("qq: HTTP %s invalid response: %w (body=%s)", action, err, string(raw))
} Defensive patterns
Strategy: validation
Validate before calling
// Go: sanity-check the endpoint returns OneBot JSON before use
resp, err := http.Get("http://127.0.0.1:5700/get_version_info")
if err != nil { return err }
var probe struct{ RetCode int `json:"retcode"` }
if json.NewDecoder(resp.Body).Decode(&probe) != nil || resp.Header.Get("Content-Type") == "text/html" {
return fmt.Errorf("endpoint does not speak OneBot JSON")
} Try / catch
if err != nil {
return fmt.Errorf("qq api returned non-JSON body (check endpoint URL and proxies)")
} Prevention
- Point config at the OneBot HTTP API port, not the web UI.
- Add Content-Type checking (application/json) before unmarshaling in your own probes.
- Pin/test your OneBot server version after upgrades.
When it happens
Trigger: json.Unmarshal(raw, &apiResp) fails in callHTTPAPI: endpoint returned HTML (error page), empty body, truncated JSON, or a non-OneBot API at the configured URL.
Common situations: Configured URL points at a web UI instead of the OneBot HTTP API; proxy returns an HTML error page; server returned a 5xx with a non-JSON body; version change in the OneBot implementation altering the response format.
Understand the failure class
Background: "Invalid JSON response" and "Failed to parse response" errors: when an API answers 200 but the body isn't the JSON your library expected — this error's family across 28 libraries.
Related errors
- googlechat: parse create response: %w
- wecom: decode send response: %w
- parse existing Agy hooks %s: %w
- marshal Agy permission hook: %w
- marshal Agy hooks overlay: %w
AI-assisted analysis of chenhg5/cc-connect@4000b2338a (2026-09-06).
Data as JSON: /api/errors/f9e038f0655770ad.
Report an issue: GitHub.