fix(xueqiu): fix 400 errors — use browser cookies, correct UA and Referer, fix hot posts endpoint#210
Open
MatrixA wants to merge 1 commit intoPanniantong:mainfrom
Open
fix(xueqiu): fix 400 errors — use browser cookies, correct UA and Referer, fix hot posts endpoint#210MatrixA wants to merge 1 commit intoPanniantong:mainfrom
MatrixA wants to merge 1 commit intoPanniantong:mainfrom
Conversation
The Xueqiu stock API requires a login session token (xq_a_token) that is generated by Xueqiu's frontend JavaScript and cannot be obtained by simply visiting the homepage. This caused persistent HTTP 400 (error code 400016) for all users. Changes: - _ensure_cookies(): add three-level priority — config file (saved by --from-browser) → live Chrome cookies via browser_cookie3 → homepage fallback. The homepage-only approach only ever got acw_tc (anti-DDoS token), never xq_a_token. - _get_json(): switch User-Agent from "agent-reach/1.0" to a real Chrome UA, and add Referer: https://xueqiu.com/ to all API requests. - get_hot_posts(): replace the defunct /statuses/hot/listV3.json endpoint (returns empty body) with the v4 public timeline endpoint; correctly parse item.data as a JSON string to extract author, text, and likes. - cookie_extract.py: add Xueqiu to PLATFORM_SPECS and configure_from_browser so that `agent-reach configure --from-browser chrome` now also saves Xueqiu cookies (only when xq_a_token is present). - check(): improve error message to direct users to --from-browser instead of suggesting a proxy. - Fix urllib.parse.quote usage (was using urllib.request.quote). - Update tier and backends description to reflect cookie requirement. - Add 2 new tests: cookie loading from config, Referer/UA header verification. - Update docs: README, install guide, troubleshooting, SKILL.md, CHANGELOG.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Xueqiu returns HTTP 400 (`error_code: 400016`) for all API calls regardless of proxy setup. This is not a network issue — it's an auth issue in the code itself.
Root cause: the stock API requires `xq_a_token`, a session token generated by Xueqiu's frontend JavaScript. Visiting the homepage via `urllib.request` only ever yields `acw_tc` (an anti-DDoS cookie). `xq_a_token` is never obtainable this way, so `_ensure_cookies()` was fundamentally insufficient.
Additional issues found during investigation:
Changes
`agent_reach/channels/xueqiu.py`
`agent_reach/cookie_extract.py`
`tests/test_channels.py`
Docs (style kept minimal, consistent with existing tone)
Testing
End-to-end verified locally with real browser cookies: