fish2018/pansou · error
无法提取qrid
Error message
无法提取qrid
What it means
Raised by generateQRCodeWithSig when the regex "qrid":"([^"]+)" finds no qrid in the info page body. api_key extraction succeeded (error 751 did not fire), but the qrid needed to poll QR scan status is absent, so QR generation aborts. This means the endpoint response is missing the expected qrid JSON field.
Solutions
- Dump infoText on failure to inspect the actual response structure around qrid.
- Update the qrid regex/parsing to match the current response format (e.g. accept qrid without quotes or nested JSON).
- Re-request the info page with proper headers/cookies; a stale or anonymous session may get a degraded response.
- Retry generation once — transient truncation or a race with session setup can omit qrid.
Example fix
// before
qridMatch := qridRegex.FindStringSubmatch(infoText)
if len(qridMatch) < 2 {
return nil, "", fmt.Errorf("无法提取qrid")
}
// after: accept both quoted JSON and bare forms
qridRegex := regexp.MustCompile(`"?qrid"?\s*[=:]\s*"?([A-Za-z0-9_-]+)`)
qridMatch := qridRegex.FindStringSubmatch(infoText)
if len(qridMatch) < 2 {
return nil, "", fmt.Errorf("无法提取qrid, 响应长度: %d", len(infoText))
} Defensive patterns
Strategy: validation
Validate before calling
// Go: confirm qrid is present in the body before relying on it
if !strings.Contains(infoText, "qrid") {
return fmt.Errorf("info response has no qrid field (len=%d)", len(infoText))
} Type guard
func hasQRID(infoText string) bool {
return regexp.MustCompile(`"?qrid"?\s*[=:]\s*"?([A-Za-z0-9_-]+)`).MatchString(infoText)
} Try / catch
qr, _, err := plugin.GenerateQRCodeWithSig(...)
if err != nil {
if strings.Contains(err.Error(), "无法提取qrid") {
// response shape drift; refetch once before giving up
return retryOrFail(err)
}
return err
} Prevention
- Refetch the info page when qrid is missing; a partial or degraded response is often transient.
- Make the qrid parser tolerant of both quoted-JSON and bare key=value formats.
- Log the body (truncated) on extraction failure to catch Weibo format changes quickly.
- Verify api_key and qrid come from the same successful response; don't mix across requests.
When it happens
Trigger: generateQRCodeWithSig (called by handleGetStatus, handleRefreshQRCode) successfully extracts api_key but qridRegex.FindStringSubmatch returns fewer than 2 groups on the same infoText.
Common situations: Weibo changed the response format (qrid renamed or nested differently); a partial/error response that still contains api_key but not qrid; response truncated by a proxy or size limit; endpoint serving different content per region or session state.
Related errors
AI-assisted analysis of fish2018/pansou@beaa561337 (2026-09-07).
Data as JSON: /api/errors/e2584f56bcc0fcea.
Report an issue: GitHub.
Appendix: source
Thrown at plugin/weibo/weibo.go:1819
return nil, "", err
}
// 响应是JSONP格式,提取JSON部分
infoText := string(infoBody)
// 提取api_key: 正则 api_key=(.*)"
apiKeyRegex := regexp.MustCompile(`api_key=([^"]+)`)
apiKeyMatch := apiKeyRegex.FindStringSubmatch(infoText)
if len(apiKeyMatch) < 2 {
return nil, "", fmt.Errorf("无法提取api_key")
}
apiKey := apiKeyMatch[1]
// 提取qrid: 正则 "qrid":"(.*?)"
qridRegex := regexp.MustCompile(`"qrid":"([^"]+)"`)
qridMatch := qridRegex.FindStringSubmatch(infoText)
if len(qridMatch) < 2 {
return nil, "", fmt.Errorf("无法提取qrid")
}
qrid := qridMatch[1]
// 第二步:使用api_key获取二维码图片
qrImageURL := fmt.Sprintf("https://v2.qr.weibo.cn/inf/gen?api_key=%s", apiKey)
qrReq, err := http.NewRequest("GET", qrImageURL, nil)
if err != nil {
return nil, "", err
}
qrReq.Header.Set("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.111 Safari/537.36")
qrReq.Header.Set("Referer", "https://weibo.com/")
qrResp, err := client.Do(qrReq)
if err != nil {
return nil, "", err
}View on GitHub (pinned to beaa561337)