DIYgod/RSSHub · error · Error

The number of attempts has exceeded 5 times

Error message

The number of attempts has exceeded 5 times

What it means

Generic Error thrown by the recursive doGot helper after more than 5 attempts to satisfy the bt0 anti-bot cookie challenge. doGot re-requests the endpoint whenever the body is an HTML page that sets a document.cookie; if it still gets a challenge page after the 5th attempt, this guard stops the recursion.

Source

Thrown at lib/routes/bt0/util.ts:9

import { CookieJar } from 'tough-cookie';

import got from '@/utils/got';

const cookieJar = new CookieJar();

async function doGot(num, host, link) {
    if (num > 4) {
        throw new Error('The number of attempts has exceeded 5 times');
    }
    const response = await got.get(link, {
        cookieJar,
    });
    const data = response.data;
    if (typeof data === 'string') {
        const regex = /document\.cookie\s*=\s*"([^"]*)"/;
        const match = data.match(regex);
        if (!match) {
            throw new Error('api error');
        }
        cookieJar.setCookieSync(match[1], host);
        return doGot(num + 1, host, link);
    }
    return data;
}

const genSize = (sizeStr) => {

View on GitHub (pinned to bed535e087)

Solutions

  1. Open the bt0 endpoint in a browser and confirm the challenge still uses `document.cookie="..."`; update the regex in doGot if the format changed.
  2. Verify the cookieJar is applying cookies to the correct host (the `host` argument passed to setCookieSync).
  3. Retry later — the challenge loop can be triggered by aggressive polling/rate-limiting from the server IP.
  4. If the API moved, update _link construction in the calling route (mv.ts / tlist.ts).

Example fix

// before
if (num > 4) {
    throw new Error('The number of attempts has exceeded 5 times');
}
// after (expose the last body snippet so the regex miss is diagnosable)
if (num > 4) {
    throw new Error('bt0 anti-bot challenge not satisfied after 5 attempts — cookie regex may be stale');
}
Defensive patterns

Strategy: retry

Validate before calling

// Bound recursion explicitly and expose a diagnosable message:
async function doGot(num: number, host: string, link: string) {
    if (num > 4) throw new Error('bt0 anti-bot challenge not satisfied after 5 attempts');
    // ...
}

Try / catch

// doGot is itself the retry mechanism. From the caller, treat exhaustion as retryable:
try {
    const data = await doGot(0, host, link);
} catch (e) {
    if (/exceeded 5 times|api error/.test((e as Error).message)) { /* retry once after delay */ }
    throw e;
}

Prevention

When it happens

Trigger: doGot is called with num > 4, i.e. the initial call plus 5 recursive retries all received string (HTML) bodies that set cookies but never resolved to the JSON payload. The cookie challenge loop never converges.

Common situations: The bt0 site changed its anti-bot mechanism so the regex no longer extracts a valid cookie; the extracted cookie is not being applied (cookieJar domain mismatch); the server keeps issuing fresh challenges for the IP; the endpoint moved.

Related errors


AI-assisted analysis of DIYgod/RSSHub@bed535e087 (2026-08-12). Data as JSON: /api/errors/2388838407f74463. Report an issue: GitHub.