RayWangQvQ/BiliBiliToolPro · error · Exception
查询白虎环境变量失败:
Error message
查询白虎环境变量失败:{envListRe.Msg} What it means
Thrown by SaveCookieToBaihuAsync when the Baihu GetEnvsAsync call returns Code != 200, meaning the environment-variable listing request to the Baihu service failed. The exception includes the service's Msg field for diagnosis.
Solutions
- Read envListRe.Msg in the exception message to see the service's stated reason.
- Regenerate the Baihu API token and update the Baihu:Token configuration.
- Confirm the token has permission to list environment variables on the Baihu service.
- Verify the Baihu API base URL and that the service is reachable.
Defensive patterns
Strategy: try-catch
Validate before calling
// pre-check token shape
var token = baihuOptions.Value.Token;
if (string.IsNullOrWhiteSpace(token) || token.Length < 20)
throw new Exception("Baihu:Token 看起来无效,请重新生成"); Try / catch
try
{
await loginDomainService.SaveCookieToBaihuAsync(ck);
}
catch (Exception ex) when (ex.Message.Contains("查询白虎环境变量失败"))
{
logger.LogError("白虎环境变量查询失败,多为token失效:{msg}", ex.Message);
// regenerate token and update config
} Prevention
- Regenerate the Baihu token when it expires and update config promptly.
- Don't double-prefix the token with 'Bearer ' — the code adds it if missing.
- Confirm the Baihu account has env-listing permissions.
When it happens
Trigger: baihuApi.GetEnvsAsync(token) responds with Code != 200 — invalid or expired bearer token, insufficient permissions on the Baihu account, or the Baihu service returning an error envelope.
Common situations: Baihu token revoked or rotated since configuration; token string pasted without/with wrong 'Bearer ' prefix (code auto-prefixes, double prefixes can also fail); Baihu service endpoint or API version changed.
Understand the failure class
Background: "API error: {status}" and "HTTP 401/403/404/429/5xx" errors: non-2xx HTTP responses explained — this error's family across 27 libraries.
Related errors
AI-assisted analysis of RayWangQvQ/BiliBiliToolPro@c599b2c0da (2026-09-12).
Data as JSON: /api/errors/75b77037567e5652.
Report an issue: GitHub.
Appendix: source
Thrown at src/Ray.BiliBiliTool.DomainService/LoginDomainService.cs:421
)
{
try
{
var token = baihuOptions.Value.Token;
if (string.IsNullOrEmpty(token))
{
throw new Exception("未配置白虎API Token");
}
if (!token.StartsWith("Bearer ", StringComparison.OrdinalIgnoreCase))
{
token = $"Bearer {token}";
}
var envListRe = await baihuApi.GetEnvsAsync(token);
if (envListRe.Code != 200)
{
throw new Exception($"查询白虎环境变量失败:{envListRe.Msg}");
}
var list = envListRe
.Data.Where(x => x.Name.StartsWith("Ray_BiliBiliCookies__"))
.ToList();
var oldEnv = list.FirstOrDefault(x => x.Value.Contains(ckInfo.UserId));
if (oldEnv != null)
{
logger.LogInformation("用户已存在,更新白虎环境变量");
logger.LogInformation("Key:{key}", oldEnv.Name);
oldEnv.Value = ckInfo.CookieStr;
oldEnv.Remark = string.IsNullOrEmpty(oldEnv.Remark)
? $"bili-{ckInfo.UserId}"
: oldEnv.Remark;
var updateRe = await baihuApi.UpdateEnvAsync(oldEnv.Id, oldEnv, token);View on GitHub (pinned to c599b2c0da)