RayWangQvQ/BiliBiliToolPro · error · BiliBusinessException

获取二维码失败:

Error message

获取二维码失败:{re.ToJsonStr()}

What it means

Thrown by LoginByQrCodeAsync when the passport API's GenerateQrCode call returns a non-zero code, meaning Bilibili refused to issue a login QR code. The library wraps the whole serialized response in BiliBusinessException so the caller can see the exact API error.

Solutions

  1. Inspect the serialized response in the exception message to read the specific code and message.
  2. Wait a few minutes and retry — QR generation is rate-limited by Bilibili.
  3. Check proxy/VPN settings that may interfere with the passport API.
  4. Upgrade Ray.BiliBiliTool in case the passport qrcode endpoint changed.
Defensive patterns

Strategy: retry

Try / catch

try
{
    var cookie = await loginDomainService.LoginByQrCodeAsync();
}
catch (BiliBusinessException ex) when (ex.Message.Contains("获取二维码失败"))
{
    logger.LogWarning("二维码生成失败,稍后重试:{msg}", ex.Message);
    await Task.Delay(TimeSpan.FromMinutes(2));
    // retry once
}

Prevention

When it happens

Trigger: passportApi.GenerateQrCode returns re.Code != 0 — e.g. request throttled by Bilibili (too many QR generations), network/proxy interception, or a Bilibili-side passport API outage.

Common situations: Running the login flow repeatedly in a short period; corporate proxy or VPN returning error responses; Bilibili changing the qrcode generation endpoint (old clients get non-zero codes).

Related errors


AI-assisted analysis of RayWangQvQ/BiliBiliToolPro@c599b2c0da (2026-09-12). Data as JSON: /api/errors/acfc5775ef8a70b3. Report an issue: GitHub.

Appendix: source

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

    ILogger<LoginDomainService> logger,
    IPassportApi passportApi,
    IHostEnvironment hostingEnvironment,
    IQingLongApi qingLongApi,
    IBaihuApi baihuApi,
    IHomeApi homeApi,
    IConfiguration configuration,
    IOptions<QingLongOptions> qingLongOptions,
    IOptions<BaihuOptions> baihuOptions
) : ILoginDomainService
{
    public async Task<BiliCookie> LoginByQrCodeAsync(CancellationToken cancellationToken)
    {
        BiliCookie? cookieInfo = null;

        var re = await passportApi.GenerateQrCode();
        if (re.Code != 0)
        {
            throw new BiliBusinessException($"获取二维码失败:{re.ToJsonStr()}");
        }

        var url = re.Data.Url;
        GenerateQrCode(url);

        var online = GetOnlinePic(url);
        logger.LogInformation(Environment.NewLine + Environment.NewLine);
        logger.LogInformation(
            "如果上方二维码显示异常,或扫描失败,请使用浏览器访问如下链接,查看高清二维码:"
        );
        logger.LogInformation(online + Environment.NewLine + Environment.NewLine);

        var waitTimes = 10;
        logger.LogInformation("我数到{num},动作快点", waitTimes);
        for (int i = 0; i < waitTimes; i++)
        {
            logger.LogInformation("[{num}]等待扫描...", i + 1);

View on GitHub (pinned to c599b2c0da)