BigPizzaV3/CodexPlusPlus · error
微信二维码响应缺少必要字段
Error message
微信二维码响应缺少必要字段
What it means
After a successful HTTP response, fetch_qr_code deserializes the body into WeixinQrCode and validates that both qr_code and qr_content are non-empty; if either is missing or blank it bails with this message. This guards against servers returning 200 with an unusable/partial payload.
Solutions
- Log the raw response body to inspect what fields were actually returned
- Check for a WeChat API schema update and update the WeixinQrCode struct/serde attributes
- Retry the request — a transiently empty payload usually succeeds on retry
- Confirm you are hitting the real API, not a stub/proxy returning empty JSON
Example fix
// before
let qr: WeixinQrCode = serde_json::from_slice(&bytes)?; // missing field => panic-ish bail
// after
#[derive(Deserialize)]
struct WeixinQrCode {
#[serde(default)]
qr_code: String,
#[serde(default, alias = "qrImg")]
qr_content: String, // tolerate renamed fields via alias
} Defensive patterns
Strategy: validation
Validate before calling
#[derive(serde::Deserialize)]
struct WeixinQrCode { qr_code: String, qr_content: String }
fn qr_payload_ok(bytes: &[u8]) -> bool {
serde_json::from_slice::<WeixinQrCode>(bytes)
.map(|q| !q.qr_code.trim().is_empty() && !q.qr_content.trim().is_empty())
.unwrap_or(false)
} Type guard
fn is_valid_qr(q: &WeixinQrCode) -> bool {
!q.qr_code.trim().is_empty() && !q.qr_content.trim().is_empty()
} Try / catch
let qr = fetch_qr_code(base_url).await.inspect_err(|e| {
if e.to_string().contains("缺少必要字段") { log_raw_response(); }
})?; Prevention
- Log raw response bodies on validation failure
- Pin/alert on WeChat API schema changes
- Retry once — empty 200 payloads are often transient
- Use a real endpoint, not a stub, in production paths
When it happens
Trigger: The WeChat QR endpoint returns HTTP 200 but the JSON body lacks `qr_code` or `qr_content`, or contains them as empty/whitespace-only strings.
Common situations: WeChat API changed its response schema (fields renamed); service degradation returning empty payloads with 200; a proxy/captive portal injecting HTML that coincidentally parses or a stub server in dev returning {}.
Related errors
AI-assisted analysis of BigPizzaV3/CodexPlusPlus@b1ed92e5e4 (2026-09-19).
Data as JSON: /api/errors/6a416018ed07b4a4.
Report an issue: GitHub.
Appendix: source
Thrown at crates/codex-plus-core/src/connect/weixin.rs:161
let client = Self::new(base_url, "", route_tag)?;
let mut url = client.endpoint("ilink/bot/get_bot_qrcode")?;
url.query_pairs_mut().append_pair("bot_type", "3");
let response = client
.client
.get(url)
.headers(client.route_headers(false)?)
.timeout(Duration::from_secs(40))
.send()
.await
.context("获取微信登录二维码失败")?;
let (status, bytes) =
read_response_limited(response, MAX_SMALL_RESPONSE_BYTES, "微信二维码").await?;
if !status.is_success() {
bail!("获取微信登录二维码失败:HTTP {status}");
}
let qr: WeixinQrCode = serde_json::from_slice(&bytes).context("微信二维码响应格式无效")?;
if qr.qr_code.trim().is_empty() || qr.qr_content.trim().is_empty() {
bail!("微信二维码响应缺少必要字段");
}
Ok(qr)
}
pub async fn poll_qr_status(
base_url: &str,
route_tag: &str,
qr_code: &str,
) -> anyhow::Result<WeixinQrStatus> {
let client = Self::new(base_url, "", route_tag)?;
let mut url = client.endpoint("ilink/bot/get_qrcode_status")?;
url.query_pairs_mut().append_pair("qrcode", qr_code);
let response = client
.client
.get(url)
.headers(client.route_headers(true)?)
.timeout(Duration::from_secs(40))
.send()View on GitHub (pinned to b1ed92e5e4)