{"record":{"id":"c27f5678c186fd5e","repo":"jackwener/OpenCLI","slug":"http-c27f56","errorCode":null,"errorMessage":"http","messagePattern":"http","errorType":"exception","errorClass":"CommandExecutionError","httpStatus":null,"severity":"error","filePath":"clis/xueqiu/auth.js","lineNumber":43,"sourceCode":"      const d = await res.json();\n      if (d?.error_code === 60201) {\n        return { kind: 'auth', detail: 'xueqiu portfolio API error_code 60201 用户id无效 — anonymous' };\n      }\n      if (d?.error_code) {\n        return { kind: 'xq-error', errorCode: d.error_code, detail: d.error_description || 'xueqiu API error' };\n      }\n      const uCookie = document.cookie.split('; ').find(c => c.startsWith('u='))?.split('=')[1] || '';\n      const cookiesuCookie = document.cookie.split('; ').find(c => c.startsWith('cookiesu='))?.split('=')[1] || '';\n      if (!uCookie || uCookie === cookiesuCookie) {\n        return { kind: 'auth', detail: 'xueqiu u cookie equals cookiesu (device id) — anonymous despite portfolio API 200' };\n      }\n      return { ok: true, user_id: uCookie };\n    } catch (e) {\n      return { kind: 'exception', detail: String(e && e.message || e) };\n    }\n  })()`);\n  if (probe?.kind === 'auth') throw new AuthRequiredError('xueqiu.com', probe.detail);\n  if (probe?.kind === 'http') throw new CommandExecutionError(`HTTP ${probe.httpStatus} from xueqiu stock API: ${probe.detail || ''}`);\n  if (probe?.kind === 'xq-error') throw new CommandExecutionError(`xueqiu API error_code ${probe.errorCode}: ${probe.detail}`);\n  if (probe?.kind === 'exception') throw new CommandExecutionError(`xueqiu whoami failed: ${probe.detail}`);\n  if (!probe?.ok) throw new CommandExecutionError(`Unexpected xueqiu probe: ${JSON.stringify(probe)}`);\n  return { user_id: String(probe.user_id) };\n}\n\nregisterSiteAuthCommands({\n  site: 'xueqiu',\n  domain: 'xueqiu.com',\n  loginUrl: 'https://xueqiu.com/',\n  columns: ['user_id'],\n  quickCheck: hasXueqiuAccessToken,\n  verify: verifyXueqiuIdentity,\n  poll: async (page) => {\n    if (!await hasXueqiuAccessToken(page)) {\n      throw new AuthRequiredError('xueqiu.com', 'Waiting for Xueqiu xq_a_token cookie');\n    }\n    return verifyXueqiuIdentity(page);","sourceCodeStart":25,"sourceCodeEnd":61,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/xueqiu/auth.js#L25-L61","documentation":"verifyXueqiuIdentity probes the xueqiu stock API inside the browser to confirm the session is logged in. When the probe reports kind 'http' (any non-OK HTTP status, notably 403 anti-bot/rate limit), it wraps the result into a CommandExecutionError with the status and detail. It signals the site rejected the authenticated API request at the HTTP layer rather than via an auth envelope.","triggerScenarios":"Running the xueqiu auth verify flow when the in-page fetch to https://stock.xueqiu.com/v5/stock/portfolio/stock/list.json returns a non-2xx status: res.status === 403 (anti-bot / rate limit) or any other !res.ok status.","commonSituations":"Hitting xueqiu's Aliyun WAF/rate limiter after too many rapid verify calls; a logged-out or stale session that gets 403 instead of a JSON error envelope; xueqiu changing the portfolio endpoint so it returns 404/5xx.","solutions":["Wait and back off, then retry — 403 usually means anti-bot or rate limiting","Open https://xueqiu.com/ in the automation browser, complete any captcha/challenge, and re-login so xq_a_token and u cookies are fresh","Re-run the verify command with --verbose to see the full HTTP status and detail","If a non-403 status persists (e.g. 404), check whether xueqiu changed the portfolio API endpoint"],"exampleFix":"// before (retrying immediately in a loop)\nawait verifyXueqiuIdentity(page);\n// after (back off on 403 before retrying)\nawait new Promise(r => setTimeout(r, 5000));\nawait verifyXueqiuIdentity(page);","handlingStrategy":"retry","validationCode":"const cookies = await page.getCookies({ url: 'https://xueqiu.com' });\nconst hasToken = cookies.some(c => c.name === 'xq_a_token' && c.value);\nif (!hasToken) throw new Error('Login to xueqiu first: xq_a_token cookie missing');","typeGuard":"function isHttpProbe(p) {\n  return !!p && typeof p === 'object' && p.kind === 'http' && typeof p.httpStatus === 'number';\n}","tryCatchPattern":"try {\n  await verifyXueqiuIdentity(page);\n} catch (e) {\n  if (/HTTP 403/.test(e.message)) {\n    await new Promise(r => setTimeout(r, 10_000)); // back off anti-bot\n    await verifyXueqiuIdentity(page);\n  } else throw e;\n}","preventionTips":["Always complete xueqiu login before running verify or data commands","Space out verify calls to avoid triggering Aliyun WAF rate limits","Run with --verbose when diagnosing so the HTTP status and detail are visible","Keep the automation browser on xueqiu.com and solve any captcha promptly"],"tags":["http","anti-bot","xueqiu","rate-limit"],"backgroundTag":"http-403-anti-bot","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}