xtekky/gpt4free · error · NoValidHarFileError
No .har file found
Error message
No .har file found
What it means
Raised by get_har_files() when the cookies directory is readable but contains no .har files (the os.walk over the top level finds nothing ending in .har). The HAR capture of a ChatGPT browser session is the credential source for this auth flow, so without it the flow cannot proceed.
Source
Thrown at g4f/Provider/openai/har_file.py:61
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:
# Error: not a HAR file!
continue
for v in harFile["log"]["entries"]:
v_headers = get_headers(v)
if arkose_url == v["request"]["url"]:
request_config.arkose_request = parseHAREntry(v)
elif v["request"]["url"].startswith(start_url):
try:View on GitHub (pinned to 973504e177)
Solutions
- Capture a .har file: open ChatGPT in DevTools > Network, reload, send one message, 'Save all as HAR'
- Save it as something.har directly inside the har_and_cookies directory (not a subdirectory)
- Strip double extensions so the file genuinely ends in .har
- Alternatively use a different OpenAI auth method that doesn't need HAR files
Defensive patterns
Strategy: validation
Validate before calling
import os
from g4f.cookies import get_cookies_dir
har_files = [f for f in os.listdir(get_cookies_dir()) if f.endswith('.har')]
if not har_files:
raise SystemExit('Capture a .har from a ChatGPT session and place it in har_and_cookies/') Try / catch
from g4f.errors import NoValidHarFileError
try:
cfg = await get_request_config(request_config, proxy)
except NoValidHarFileError as e:
if 'No .har file' in str(e):
guide_user_to_capture_har() # or switch auth method
raise Prevention
- Capture the HAR during an active chat message, saved as *.har at the top level of the cookies dir
- Avoid double extensions like .har.txt
- Automate a pre-flight check for .har presence before starting HAR-auth flows
When it happens
Trigger: Using OpenAI-with-HAR auth with an empty har_and_cookies directory, or one containing only cookie files (.json/.txt) and no .har capture.
Common situations: User exported cookies instead of a HAR capture; HAR file saved with a different extension (.har.txt); files placed in a subdirectory while the walk only scans the top level (note the `break` after the first iteration).
Related errors
- har_and_cookies dir is not readable
- The .har file is not valid
- No proof_token found in .har files
- ANTIGRAVITY_SERVICE_ACCOUNT environment variable not set. Pl
- Invalid response: {last_msg}
AI-assisted analysis of xtekky/gpt4free@973504e177 (2026-08-14).
Data as JSON: /api/errors/4cb36c92d2c84f41.
Report an issue: GitHub.