xtekky/gpt4free · error · NoValidHarFileError

har_and_cookies dir is not readable

Error message

har_and_cookies dir is not readable

What it means

Raised by get_har_files() in the OpenAI HAR-based auth flow when the cookies directory (get_cookies_dir(), i.e. har_and_cookies) is not readable by the process (os.access R_OK fails). NoValidHarFileError indicates an environment/permission problem: the .har files that supply proof tokens and Arkose data cannot even be listed.

Source

Thrown at g4f/Provider/openai/har_file.py:53

    turnstile_token: str = None
    arkose_request: arkReq = None
    arkose_token: str = None
    data_build: str = "prod-db8e51e8414e068257091cf5003a62d3d4ee6ed0"


class arkReq:
    def __init__(self, arkURL, arkBx, arkHeader, arkBody, arkCookies, userAgent):
        self.arkURL = arkURL
        self.arkBx = arkBx
        self.arkHeader = arkHeader
        self.arkBody = arkBody
        self.arkCookies = arkCookies
        self.userAgent = userAgent


def get_har_files():
    if not os.access(get_cookies_dir(), os.R_OK):
        raise NoValidHarFileError("har_and_cookies dir is not readable")
    harPath = []
    for root, _, files in os.walk(get_cookies_dir()):
        for file in files:
            if file.endswith(".har"):
                harPath.append(os.path.join(root, file))
        break
    if not harPath:
        raise NoValidHarFileError("No .har file found")
    harPath.sort(key=lambda x: os.path.getmtime(x))
    return harPath


def readHAR(request_config: RequestConfig):
    for path in get_har_files():
        with open(path, "rb") as file:
            try:
                harFile = json.loads(file.read())
            except json.JSONDecodeError:

View on GitHub (pinned to 973504e177)

Solutions

  1. Check permissions: ls -ld <cookies_dir> and fix with chmod/chown (e.g. chmod 755)
  2. In Docker, ensure the volume containing har_and_cookies is readable by the container user
  3. Verify the directory path get_cookies_dir() resolves to exists and is the intended one
  4. Run as the user that owns the directory or chown it to the runtime user

Example fix

# before
$ ls -ld ~/.config/har_and_cookies
drwx------ root root
# after
$ sudo chown -R $(id -u):$(id -g) ~/.config/har_and_cookies
$ chmod 755 ~/.config/har_and_cookies
Defensive patterns

Strategy: validation

Validate before calling

import os
from g4f.cookies import get_cookies_dir

cookies_dir = get_cookies_dir()
if not os.access(cookies_dir, os.R_OK):
    raise SystemExit(f'Fix permissions on {cookies_dir}: chmod 755')

Prevention

When it happens

Trigger: Running the OpenAI provider with HAR auth while the har_and_cookies directory has no read permission for the current user (bad chmod, wrong container user, SELinux/AppArmor denial).

Common situations: Docker containers running as non-root with restrictive volume permissions; files copied with root ownership; directory permissions changed accidentally; read-only mounts.

Related errors


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