xtekky/gpt4free · critical · NoValidHarFileError

No session found in .har files

Error message

No session found in .har files

What it means

Immediately after a successful dlopen, the C runner dlsyms six required symbols (PyConfig_InitPythonConfig, PyConfig_SetBytesArgv, PyConfig_SetBytesString, PyConfig_Clear, Py_InitializeFromConfig, Py_RunMain). If any is missing it prints this and exits 1. It means the loaded libpython3.14.so is not a full CPython 3.14 shared library exposing the stable/embedding API.

Source

Thrown at g4f/Provider/Copilot.py:545

        with open(path, "rb") as file:
            try:
                harFile = json.loads(file.read())
            except json.JSONDecodeError:
                # Error: not a HAR file!
                continue
            for v in harFile["log"]["entries"]:
                if v["request"]["url"].startswith(url):
                    v_headers = get_headers(v)
                    if "authorization" in v_headers:
                        api_key = v_headers["authorization"].split(maxsplit=1).pop()
                    if "x-useridentitytype" in v_headers:
                        useridentitytype = v_headers["x-useridentitytype"]
                    if v["request"]["cookies"]:
                        cookies = {
                            c["name"]: c["value"] for c in v["request"]["cookies"]
                        }
    if not cookies:
        raise NoValidHarFileError("No session found in .har files")

    return api_key, useridentitytype, cookies


if has_nodriver:

    async def click_trunstile(
        page: nodriver.Tab, element='document.getElementById("cf-turnstile")'
    ):
        for _ in range(3):
            size = None
            for idx in range(15):
                size = await page.js_dumps(f"{element}?.getBoundingClientRect()||{{}}")
                debug.log(f"Found size: {size.get('x'), size.get('y')}")
                if "x" not in size:
                    break
                await page.flash_point(size.get("x") + idx * 3, size.get("y") + idx * 3)
                await page.mouse_click(size.get("x") + idx * 3, size.get("y") + idx * 3)

View on GitHub (pinned to 973504e177)

Solutions

  1. Verify which library actually loaded: run with LD_DEBUG=libs (or check /proc/self/maps) and confirm it is <binDir>/python-home/lib/libpython3.14.so, not a system/Termux copy found earlier on the search path
  2. Check symbol presence: nm -D python-home/lib/libpython3.14.so | grep -E 'Py_InitializeFromConfig|Py_RunMain' — if absent, the runtime flavor is wrong; re-download a full pbs shared build
  3. Wipe python-home and pyandroid, re-download the runtime, and rebuild the runner so rpath and library version agree
  4. Unset or trim LD_LIBRARY_PATH/PYTHONHOME from the outer environment so the runner's rpath wins
  5. If the printed dlerror() is empty, that is expected — dlsym failure does not always set dlerror; rely on nm inspection instead
Defensive patterns

Strategy: validation

Validate before calling

# shell guard before running the runner
nm -D python-home/lib/libpython3.14.so | grep -q 'Py_InitializeFromConfig' \
  && nm -D python-home/lib/libpython3.14.so | grep -q 'Py_RunMain' \
  || echo 'libpython lacks embedding symbols; wrong runtime build'

Try / catch

// In C: fail with a per-symbol report so diagnosis does not depend on dlerror()
const char *need[] = {"PyConfig_InitPythonConfig","PyConfig_SetBytesArgv",
    "PyConfig_SetBytesString","PyConfig_Clear","Py_InitializeFromConfig","Py_RunMain"};
void *syms[6];
for (int i = 0; i < 6; i++) {
    syms[i] = dlsym(h, need[i]);
    if (!syms[i]) { fprintf(stderr, "missing python symbol: %s\n", need[i]); return 1; }
}

Prevention

When it happens

Trigger: dlopen resolved to a different libpython3.14.so on the search path (system copy, stub, or wrong build) that lacks embedding symbols; a python built with --disable-shared or an ffi-limited build loaded by mistake; ABI mismatch where dlsym returns NULL on versioned symbol lookups; dlerror() returning NULL here (common when a prior dlsym failed without setting an error), making the printed reason empty.

Common situations: LD_LIBRARY_PATH picking up Termux's own older libpython before the merged one; rpath pointing at a stale lib from a previous runtime version; fetching a python flavor whose .so exports only a subset of symbols; leftover lib from python 3.13 renamed into a 3.14 layout.

Related errors


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