{"record":{"id":"4f5e75625b5f4ded","repo":"HKUDS/Vibe-Trading","slug":"failed-to-get-qr-code-from-wechat-api-data","errorCode":null,"errorMessage":"Failed to get QR code from WeChat API: {data}","messagePattern":"Failed to get QR code from WeChat API: (.+?)","errorType":"error_code","errorClass":"RuntimeError","httpStatus":null,"severity":"critical","filePath":"agent/src/channels/weixin.py","lineNumber":337,"sourceCode":"        resp = await self._client.post(url, json=payload, headers=self._make_headers(auth=auth))\n        resp.raise_for_status()\n        return resp.json()\n\n    # ------------------------------------------------------------------\n    # QR Code Login  (matches login-qr.ts)\n    # ------------------------------------------------------------------\n\n    async def _fetch_qr_code(self) -> tuple[str, str]:\n        \"\"\"Fetch a fresh QR code. Returns (qrcode_id, scan_url).\"\"\"\n        data = await self._api_get(\n            \"ilink/bot/get_bot_qrcode\",\n            params={\"bot_type\": \"3\"},\n            auth=False,\n        )\n        qrcode_img_content = data.get(\"qrcode_img_content\", \"\")\n        qrcode_id = data.get(\"qrcode\", \"\")\n        if not qrcode_id:\n            raise RuntimeError(f\"Failed to get QR code from WeChat API: {data}\")\n        return qrcode_id, (qrcode_img_content or qrcode_id)\n\n    async def _qr_login(self) -> bool:\n        \"\"\"Perform QR code login flow. Returns True on success.\"\"\"\n        try:\n            refresh_count = 0\n            qrcode_id, scan_url = await self._fetch_qr_code()\n            self._print_qr_code(scan_url)\n            current_poll_base_url = self.config.base_url\n\n            while self._running:\n                try:\n                    status_data = await self._api_get_with_base(\n                        base_url=current_poll_base_url,\n                        endpoint=\"ilink/bot/get_qrcode_status\",\n                        params={\"qrcode\": qrcode_id},\n                        auth=False,\n                    )","sourceCodeStart":319,"sourceCodeEnd":355,"githubUrl":"https://github.com/HKUDS/Vibe-Trading/blob/80ffdda44c5c4db0dd84d70e051cca591cea67df/agent/src/channels/weixin.py#L319-L355","documentation":"Thrown when the WeChat iLink login API response for a QR-code request contains an empty 'qrcode' field. The library calls the bot_type=3 QR endpoint unauthenticated and expects data.qrcode to be a non-empty ticket string; an empty value means the server did not issue a login QR code, and the full response is embedded for diagnosis.","triggerScenarios":"Calling _fetch_qr_code (via _qr_login) where the POST to the WeChat API returns JSON lacking or with an empty 'qrcode' key — e.g. server-side rate limiting, service outage, changed response schema, or invalid bot_type parameter.","commonSituations":"Frequent re-logins triggering WeChat rate limits; WeChat iLink API schema changes after a server update; network middleboxes returning an HTML error page parsed as empty data; misconfigured bot credentials causing the server to refuse QR issuance.","solutions":["Retry the QR login after a short backoff (30-60s); transient server refusals are common.","Inspect the full response dict in the message: if it is empty/HTML, check network proxy or DNS interception.","Verify the request parameters (bot_type='3', auth=False) match the API version your account/backend supports.","Check WeChat service status and confirm the account is not temporarily blocked from iLink bot login."],"exampleFix":"// before\nqrcode_id, img = await self._fetch_qr_code()\n\n// after\nfor attempt in range(3):\n    try:\n        qrcode_id, img = await self._fetch_qr_code()\n        break\n    except RuntimeError:\n        if attempt == 2: raise\n        await asyncio.sleep(30)","handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"try:\n    qrcode_id, img = await channel._fetch_qr_code()\nexcept RuntimeError as e:\n    if \"Failed to get QR code\" in str(e):\n        await asyncio.sleep(30)  # then retry, max N times\n    else:\n        raise","preventionTips":["Retry QR issuance with 30-60s backoff.","Avoid rapid repeated logins (rate limiting).","Log the full API response embedded in the exception."],"tags":["wechat","qr-login","authentication","api-error"],"backgroundTag":"qr-code-login-failed","analyzedSha":"80ffdda44c5c4db0dd84d70e051cca591cea67df","analyzedAt":"2026-08-28T12:46:38.989Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}