BigPizzaV3/CodexPlusPlus · error

获取微信登录二维码失败:HTTP

Error message

获取微信登录二维码失败:HTTP {status}

What it means

fetch_qr_code calls the WeChat login endpoint to obtain a QR code; after reading the response (with a size cap), it checks HTTP success and bails with this message when the server returned a non-2xx status. The status code is interpolated into the message, and a lower-level context ('获取微信登录二维码失败') wraps transport errors separately.

Solutions

  1. Read the HTTP status in the message: 5xx → retry with backoff; 429 → wait before retrying; 4xx → check base_url and request shape
  2. Verify the configured WeChat API base_url is correct
  3. Retry the login flow after a short delay — transient 5xx are common
  4. Check network/proxy interference if statuses like 403/502 appear

Example fix

// before
let qr = client.fetch_qr_code(base_url).await?; // fails on transient 5xx
// after
let qr = retry_with_backoff(3, || client.fetch_qr_code(base_url)).await
    .or_else(|e| Err(anyhow!("二维码获取失败,请检查网络后重试: {e:#}")))?;
Defensive patterns

Strategy: retry

Validate before calling

// probe the endpoint health before fetching a QR
let health = reqwest::get(format!("{base_url}/health")).await?;
anyhow::ensure!(health.status().is_success(), "WeChat 服务不可用");

Try / catch

match fetch_qr_code(base_url).await {
    Err(e) if e.to_string().contains("HTTP 5") => retry_with_backoff(3, fetch_qr_code).await,
    other => other,
}

Prevention

When it happens

Trigger: The HTTP response from the WeChat QR endpoint has a non-success status (4xx/5xx), e.g. service outage, rate limiting, or a wrong base_url hitting an error page.

Common situations: WeChat login service temporarily down (5xx); wrong/misconfigured base_url; too many QR requests triggering 429; corporate proxy returning 403/502.

Understand the failure class

Background: "API error: {status}" and "HTTP 401/403/404/429/5xx" errors: non-2xx HTTP responses explained — this error's family across 27 libraries.

Related errors


AI-assisted analysis of BigPizzaV3/CodexPlusPlus@b1ed92e5e4 (2026-09-19). Data as JSON: /api/errors/6ffa4960441a301d. Report an issue: GitHub.

Appendix: source

Thrown at crates/codex-plus-core/src/connect/weixin.rs:157

        })
    }

    pub async fn fetch_qr_code(base_url: &str, route_tag: &str) -> anyhow::Result<WeixinQrCode> {
        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

View on GitHub (pinned to b1ed92e5e4)