Skip to navigation

Bilibili returns HTTP 412 or WBI signature error: how to fix it

View as Markdown

Bilibili returns two distinct anti-bot errors that have different causes:

  • HTTP 412 Precondition Failed: Your IP range, missing User-Agent or Referer, or missing buvid3 cookie triggered Bilibili’s edge firewall.
  • Business code -352 or -403 (WBI signing error): Your w_rid and wts signature is missing or expired (the daily img_key / sub_key mixin rotated), or the endpoint requires a logged-in SESSDATA cookie.

For a small local script on a home IP, fixing headers and refreshing WBI keys can resolve both errors. For cloud servers (AWS, Aliyun, Cloudflare, GitHub Actions), scheduled jobs, and AI agents, BeatAPI handles Bilibili signing and IP reputation server-side across 87 Bilibili actions starting at $0.003 per request (checked 2026-11-23; failed gateway calls cost $0).

Quick diagnosis: local fix vs. BeatAPI

SymptomLikely causeLocal fix to try firstWhen to switch to BeatAPI
HTTP 412 on first requestDatacenter IP or default python-requests User-AgentAdd a real browser User-Agent, Referer: https://www.bilibili.com/, and fetch buvid3 from /x/frontend/finger/spiStill hits 412 from a cloud VPS or CI runner
code: -352 or -403 on search/commentsMissing or expired WBI (w_rid + wts) or missing SESSDATARe-fetch img_url and sub_url from /x/web-interface/nav and recompute MD5 w_ridYou do not want personal SESSDATA cookies on a server
Works locally, breaks in productionCloud IP range is rate-limited by BilibiliRequires residential proxiesSwitch immediately ($0.003 per call costs less than a proxy pool)

Call Bilibili actions through BeatAPI

BeatAPI serves Bilibili search, video details, and comments over POST https://api.beatapi.io/v1/social-data/call and remote MCP (https://beatapi.io/mcp) without buvid3, WBI signing, or SESSDATA:

curl -sS https://api.beatapi.io/v1/social-data/call \
-H "Authorization: Bearer $BEATAPI_API_KEY" \
-H 'Content-Type: application/json' \
-d '{"action":"bilibili.web.fetch_general_search","params":{"keyword":"Rust 教程","order":"click","page":1,"page_size":20}}'

Check live inputs and pricing for $0 via POST /v1/capabilities/inspect or BeatAPI pricing.