import sys
sys.path.insert(0,
'/root/.local/share/pipx/venvs/xiaohongshu-cli/lib/python3.12/site-packages')
import json
from xhs_cli.client import XhsClient
from xhs_cli.cookies import load_saved_cookies
# Load saved cookies
cookies = load_saved_cookies()
print(f"Cookies loaded: {list(cookies.keys()) if cookies else 'None'}")
if not cookies:
# Fall back to direct file read
import json
with open('/root/.xiaohongshu-cli/cookies.json') as f:
cookies = json.load(f)
print(f"Cookies from file: {list(cookies.keys())}")
# Create client
client = XhsClient(cookies=cookies, max_retries=2)
# Try self info first (should work)
try:
info = client.get_self_info()
print(f"Self info: OK")
except Exception as e:
print(f"Self info error: {e}")
# Try favorites with debug
(b'x-alicdn-da-ups-status', b'endOs,0,406'), (b'Via', b'ens-cache19.l2hk11[41,0],
INFO:httpx:HTTP Request: GET https://edith.xiaohongshu.com/api/sns/web/v2/note/co
llect/page?user_id=59e1feaa6b64550b81aaf398&cursor=&num=30 "HTTP/1.1 406 Not
Acceptable"
DEBUG:httpcore.http11:receive_response_body.started request=<Request [b'GET']>
DEBUG:httpcore.http11:receive_response_body.complete
DEBUG:httpcore.http11:response_closed.started
DEBUG:httpcore.http11:response_closed.complete
Cookies loaded: ['web_session', 'id_token', 'a1']
Self info: OK
Favorites error: XhsApiError: API error: {"code": -1, "success": false
Bug 描述 | Bug Description
收藏 API 失败原因
xhs favorites 调用 GET /api/sns/web/v2/note/collect/page 时,服务器返回 HTTP
406(签名验证失败)。这是 xiaohongshu-cli v0.6.4 的已知 bug,目前是最新版本,xhshow
签名库对该接口的签名算法不完整。
复现步骤 | Steps to Reproduce
期望行为 | Expected Behavior
访问成功
实际行为 | Actual Behavior
挂了
代码示例 | Code Sample
如上错误堆栈 | Error Traceback
xhshow 版本 | xhshow Version
0.1.9
Python 版本 | Python Version
3.12
操作系统 | Operating System
ubuntu 22.04
补充信息 | Additional Context
No response