RayWangQvQ/BiliBiliToolPro · error · BiliIntegrationException

查询环境变量失败:

Error message

查询环境变量失败:{qlEnvList.ToJsonStr()}

What it means

Thrown by SaveCookieToQinLongAsync when the QingLong GetEnvsAsync call returns a Code other than 200, meaning the environment-variable list query against the QingLong panel failed. The exception includes the full serialized response so the caller can see the panel's error message.

Solutions

  1. Read the serialized response in the exception to identify the panel's error (usually auth or permission related).
  2. Regenerate the QingLong app's ClientSecret and update configuration.
  3. Grant the QingLong application env read/write permissions in the panel's app settings.
  4. Verify the QingLong panel version supports the open API endpoint used.
Defensive patterns

Strategy: retry

Try / catch

try
{
    await loginDomainService.SaveCookieToQinLongAsync(ck);
}
catch (BiliIntegrationException ex) when (ex.Message.Contains("查询环境变量失败"))
{
    logger.LogError("青龙环境变量查询失败(多为token/权限问题):{msg}", ex.Message);
    // fix credentials in QingLong panel then re-run
}

Prevention

When it happens

Trigger: qingLongApi.GetEnvsAsync("Ray_BiliBiliCookies__", token) responds with Code != 200 — invalid/expired token, QingLong app lacking env read permission, or the panel returning an error envelope (auth failure, panel down).

Common situations: QingLong token expired between obtaining and using it; the QingLong application was created without environment-variable permissions; QingLong panel upgraded and the open API path/response 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/59d530b50fb195f6. Report an issue: GitHub.

Appendix: source

Thrown at src/Ray.BiliBiliTool.DomainService/LoginDomainService.cs:252

    }

    public async Task<bool> SaveCookieToQinLongAsync(
        BiliCookie ckInfo,
        CancellationToken cancellationToken
    )
    {
        try
        {
            var token = await GetQingLongAuthTokenAsync();
            if (string.IsNullOrEmpty(token))
            {
                throw new BiliIntegrationException("获取青龙token失败");
            }

            var qlEnvList = await qingLongApi.GetEnvsAsync("Ray_BiliBiliCookies__", token);
            if (qlEnvList.Code != 200)
            {
                throw new BiliIntegrationException($"查询环境变量失败:{qlEnvList.ToJsonStr()}");
            }

            logger.LogDebug(qlEnvList.Data.ToJsonStr());
            logger.LogDebug(ckInfo.ToString());

            var list = qlEnvList
                .Data.Where(x => x.name.StartsWith("Ray_BiliBiliCookies__"))
                .ToList();
            var oldEnv = list.FirstOrDefault(x => x.value.Contains(ckInfo.UserId));

            if (oldEnv != null)
            {
                logger.LogInformation("用户已存在,更新cookie");
                logger.LogInformation("Key:{key}", oldEnv.name);
                var update = new UpdateQingLongEnv
                {
                    id = oldEnv.id,
                    name = oldEnv.name,

View on GitHub (pinned to c599b2c0da)