xtekky/gpt4free · error · Exception

Error processing token {token}: {exc}

Error message

Error processing token {token}: {exc}

What it means

Raised by process_turnstile_token's dispatch loop (new.py:741) when one of the handler functions registered in process_map throws while consuming a token entry from Cloudflare's turnstile token blob. Each entry is [key, *args]; the exception is re-wrapped with the offending token, so the inner message tells you which handler failed (JSON parse, float conversion, string ops, etc.).

Source

Thrown at g4f/Provider/openai/new.py:741

        nonlocal res
        res = base64.b64encode(e.encode()).decode()

    process_map[3] = func_3
    process_map[9] = token_list
    process_map[16] = p

    for token in token_list:
        try:
            e = token[0]
            t = token[1:]
            f = process_map.get(e)
            if callable(f):
                f(*t)
            else:
                pass
                # print(f"Warning: No function found for key {e}")
        except Exception as exc:
            raise Exception(f"Error processing token {token}: {exc}")
            # print(f"Error processing token {token}: {exc}")

    return res

View on GitHub (pinned to 973504e177)

Solutions

  1. Upgrade g4f to the latest release (pip install -U g4f) to get updated turnstile handlers
  2. Inspect the inner exception text: it names the real failure (e.g. ValueError on float()) and pinpoints the changed field
  3. Retry the request — a fresh page load yields a fresh turnstile token
  4. If patching locally, add/adjust the handler in process_map for the failing key instead of swallowing the error

Example fix

// before
res = process_turnstile_token(decoded, p)  # raises Error processing token [...]

// after
try:
    res = process_turnstile_token(decoded, p)
except Exception as exc:
    print(f"turnstile token changed: {exc}")  # inspect offending token entry
    raise
Defensive patterns

Strategy: try-catch

Validate before calling

import base64
def valid_turnstile_dx(dx: str) -> bool:
    try:
        data = base64.b64decode(dx, validate=True)
        text = data.decode("utf-8")
        return len(text) > 0 and text.lstrip("[").startswith("[") or True
    except Exception:
        return False

Try / catch

try:
    token = get_turnstile_token(dx, p)
except Exception as exc:
    # inner message names the failing handler; log the offending token entry for diagnosis
    logger.error("turnstile processing failed: %s", exc)
    raise

Prevention

When it happens

Trigger: get_turnstile_token(dx, p) is called with a dx blob whose decoded token list contains a key whose handler receives malformed arguments — e.g. a float entry where a string is expected — or a new/renamed key whose handler signature changed; any Exception inside the per-token try block triggers it.

Common situations: Cloudflare changes the turnstile token encoding or field order; g4f version out of sync with the current turnstile script; truncated/corrupted base64 dx input from an intercepted response.

Related errors


AI-assisted analysis of xtekky/gpt4free@973504e177 (2026-08-14). Data as JSON: /api/errors/fae87c173c01c672. Report an issue: GitHub.