RayWangQvQ/BiliBiliToolPro · error · BiliValidationException
Cookie字符串格式异常,内部无等号
Error message
Cookie字符串格式异常,内部无等号
What it means
BiliCookie.Check validates that the cookie string was parsed into key=value items; if CookieItemDictionary is empty, no '=' was present anywhere in the configured cookie string, so it throws BiliValidationException. It fails fast before any API call is made with an unusable cookie.
Solutions
- Copy the full cookie string from browser devtools (Application > Cookies), including every 'key=value' pair separated by '; '.
- Ensure '=' characters are not stripped or double-encoded in your config source (appsettings.json, env var, CI secret).
- Validate the cookie string contains at least one '=' before constructing BiliCookie.
Example fix
// before
var cookie = new BiliCookie("abc123def456");
// after
var cookie = new BiliCookie("SESSDATA=abc123def456; bili_jct=xyz; DedeUserID=12345"); Defensive patterns
Strategy: validation
Validate before calling
if (string.IsNullOrWhiteSpace(cookieString) || !cookieString.Contains('='))
throw new ArgumentException("Cookie string must contain key=value pairs separated by ';'"); Try / catch
try { cookie.Check(); }
catch (BiliValidationException ex) { logger.LogError("Cookie 配置无效: {Msg}", ex.Message); return; } Prevention
- Always copy the full cookie string including '=' from browser devtools.
- Call Check() immediately after constructing BiliCookie to fail fast.
- Avoid hand-typing cookie values; paste them verbatim.
When it happens
Trigger: Constructing a BiliCookie from a string with no '=' characters (e.g. a raw token, a placeholder like 'xxxx', or whitespace) and calling Check(); tests deliberately pass an empty dictionary.
Common situations: User pastes only the value of SESSDATA instead of the full 'SESSDATA=...; bili_jct=...' string; cookie copied with URL-encoding stripped of '='; config env var left as a dummy value.
Understand the failure class
Background: "Invalid value" and "allowed values are" config errors: what your library rejected and how to fix it — this error's family across 41 libraries.
Related errors
- Cookie字符串异常,无[ ]项
- 请正确配置Cookie后再运行,配置方式见
- [ ]= 不能转换为long型,请确认配置的是正确的Cookie值
- Unsupported algorithm
- 登录失败,请检查Cookie
AI-assisted analysis of RayWangQvQ/BiliBiliToolPro@c599b2c0da (2026-09-12).
Data as JSON: /api/errors/e3bceb0d9ae63167.
Report an issue: GitHub.
Appendix: source
Thrown at src/Ray.BiliBiliTool.Agent/BiliCookie.cs:72
[Description("buvid3")]
public string Buvid =>
CookieItemDictionary.TryGetValue(GetPropertyDescription(nameof(Buvid)), out string? buvid)
? buvid
: "";
#endregion
/// <summary>
/// 检查是否已配置
/// </summary>
/// <returns></returns>
public override void Check()
{
base.Check();
if (CookieItemDictionary.Count == 0)
throw new BiliValidationException("Cookie字符串格式异常,内部无等号");
bool result = true;
string msg = "Cookie字符串异常,无[{0}]项";
//UserId为空,抛异常
if (string.IsNullOrWhiteSpace(UserId))
{
throw new BiliValidationException(
string.Format(msg, GetPropertyDescription(nameof(UserId)))
);
}
else if (!long.TryParse(UserId, out long uid)) //不为空,但不能转换为long,警告
{
throw new BiliValidationException(
string.Format(
"[{0}]={1} 不能转换为long型,请确认配置的是正确的Cookie值",
GetPropertyDescription(nameof(UserId)),
UserIdView on GitHub (pinned to c599b2c0da)