xtekky/gpt4free · error · TokenManagerError
TokenError.FILE_ACCESS_ERROR
TokenError.FILE_ACCESS_ERROR
Error message
Credentials file not found
What it means
TokenManagerError (code FILE_ACCESS_ERROR) raised in SharedTokenManager.reloadCredentialsFromFile when opening the credential file raises FileNotFoundError. The manager clears its in-memory cache and re-raises wrapped, so any caller that assumed persisted credentials exist fails loudly instead of silently using stale tokens.
Source
Thrown at g4f/Provider/github/sharedTokenManager.py:100
self.reloadCredentialsFromFile()
self.memory_cache["file_mod_time"] = file_mod_time
except FileNotFoundError:
self.memory_cache["file_mod_time"] = 0
except Exception as e:
self.memory_cache["credentials"] = None
raise TokenManagerError(TokenError.FILE_ACCESS_ERROR, str(e), e)
def reloadCredentialsFromFile(self):
file_path = self.getCredentialFilePath()
debug.log(f"Reloading credentials from {file_path}")
try:
with open(file_path, "r") as fs:
data = json.load(fs)
credentials = self.validateCredentials(data)
self.memory_cache["credentials"] = credentials
except FileNotFoundError as e:
self.memory_cache["credentials"] = None
raise TokenManagerError(
TokenError.FILE_ACCESS_ERROR, "Credentials file not found", e
) from e
except json.JSONDecodeError as e:
self.memory_cache["credentials"] = None
raise TokenManagerError(
TokenError.FILE_ACCESS_ERROR, "Invalid JSON format", e
) from e
except Exception as e:
self.memory_cache["credentials"] = None
raise TokenManagerError(TokenError.FILE_ACCESS_ERROR, str(e), e) from e
def validateCredentials(self, data):
if not data or not isinstance(data, dict):
raise ValueError("Invalid credentials format")
if "access_token" not in data or not isinstance(data["access_token"], str):
raise ValueError("Invalid credentials: missing access_token")
if "token_type" not in data or not isinstance(data["token_type"], str):
raise ValueError("Invalid credentials: missing token_type")View on GitHub (pinned to 973504e177)
Solutions
- Run 'g4f auth github-copilot' in the same environment/user that runs the app to create the file
- Verify getCredentialFilePath() resolves to an existing file in the runtime (check HOME/XDG_CONFIG_HOME in Docker, systemd, cron)
- Pre-create/mount the credential directory if deploying to read-only or ephemeral filesystems
Defensive patterns
Strategy: validation
Validate before calling
from pathlib import Path
cred_path = Path(sm.getCredentialFilePath())
if not cred_path.is_file():
raise SystemExit('Run g4f auth github-copilot first') Try / catch
from g4f.Provider.github.sharedTokenManager import TokenManagerError
try:
creds = await sm.getValidCredentials(client)
except TokenManagerError as e:
if 'Credentials file not found' in str(e):
creds = await do_device_login() Prevention
- Run 'g4f auth' in the same container/user as the app; bake or mount the credential file in Docker images
- Assert the credential file exists at boot
- Never assume a prior machine's login carries over
When it happens
Trigger: Any credentials read/refresh attempt (getValidCredentials, CopilotTokenProvider token exchange) when the credential JSON file does not exist at getCredentialFilePath() — typically because login never ran in this environment.
Common situations: Fresh installs; containers/CI where HOME differs from the machine where 'g4f auth' was run; credential directory wiped by cleanup tooling.
Related errors
- No refresh token found in GCP_SERVICE_ACCOUNT.
- FILE_ACCESS_ERROR
- No Yupp accounts configured. Set YUPP_API_KEY environment va
- NO_TOKEN
- Failed to obtain API key from Z.ai authentication endpoint
AI-assisted analysis of xtekky/gpt4free@973504e177 (2026-08-14).
Data as JSON: /api/errors/858d0bc9189916cf.
Report an issue: GitHub.