soxoj/maigret · error · FileNotFoundError
Problem while attempting to access data file '{filename}'.
Error message
Problem while attempting to access data file '{filename}'. What it means
load_from_file() raises FileNotFoundError('Problem while attempting to access data file ...') when open(filename) itself fails with FileNotFoundError — i.e. the path does not exist, a directory component is missing, or (on some platforms) the path is a directory. The original OSError is chained via 'from error', preserving the underlying cause. Because relative paths resolve against the process CWD, the most common cause is running the script from a different directory than the data file.
Source
Thrown at maigret/sites.py:595
else:
raise FileNotFoundError(
f"Bad response while accessing " f"data file URL '{url}'."
)
return self.load_from_json(data)
def load_from_file(self, filename: "str") -> "MaigretDatabase":
try:
with open(filename, "r", encoding="utf-8") as file:
try:
data = json.load(file)
except Exception as error:
raise ValueError(
f"Problem parsing json contents from "
f"file '{filename}': {str(error)}."
)
except FileNotFoundError as error:
raise FileNotFoundError(
f"Problem while attempting to access " f"data file '{filename}'."
) from error
return self.load_from_json(data)
def get_scan_stats(self, sites_dict):
sites = sites_dict or self.sites_dict
found_flags: Dict[str, int] = {}
for _, s in sites.items():
if "presense_flag" in s.stats:
flag = s.stats["presense_flag"]
found_flags[flag] = found_flags.get(flag, 0) + 1
return found_flags
def extract_ids_from_url(self, url: str) -> dict:
results = {}
for s in self._sites:View on GitHub (pinned to 41674631a9)
Solutions
- Print/verify the resolved path first: os.path.abspath(filename) and os.path.isfile(filename); fix the path or CWD.
- Prefer absolute paths derived from your package location: pathlib.Path(__file__).parent / 'data.json'.
- If the file is missing from a deployment, copy/vendor maigret's resources/data.json into your distribution or download it at startup.
- For missing packaged assets in Docker/bundles, add the file to the image/build and reference it by absolute path.
Example fix
# before
db = MaigretDatabase().load_from_file('resources/data.json') # breaks when CWD differs
# after
from pathlib import Path
DB_PATH = Path(__file__).resolve().parent / 'resources' / 'data.json'
assert DB_PATH.is_file(), f'missing maigret db at {DB_PATH}'
db = MaigretDatabase().load_from_file(str(DB_PATH)) Defensive patterns
Strategy: validation
Validate before calling
import os
path = os.path.abspath('resources/data.json')
if not os.path.isfile(path):
raise SystemExit(f'maigret data file not found at {path}')
db = MaigretDatabase().load_from_file(path) Type guard
import os
def file_exists(path: str) -> bool:
return os.path.isfile(os.path.abspath(path)) Try / catch
try:
db = MaigretDatabase().load_from_file(path)
except FileNotFoundError as err:
logger.error('data file missing: %s', err)
path = download_or_locate_db() # fetch known-good copy
db = MaigretDatabase().load_from_file(path) Prevention
- Reference data files with paths anchored to __file__ or absolute paths, never CWD-relative ones.
- Include resources/data.json in Docker images and bundles; verify with a smoke test at startup.
- Use MaigretDatabase.default_db() which resolves the packaged location for you.
When it happens
Trigger: Calling db.load_from_file('resources/data.json') when the file or the resources/ directory does not exist relative to the current working directory; passing an absolute path with a typo; deploying code where the data file was not packaged into the container/wheel.
Common situations: Running the tool from a different CWD than the checkout (relative path breaks), Docker images or PyInstaller bundles that omit resources/, cloned repo without fetched data files, or CI jobs on a fresh checkout where resources/data.json lives elsewhere.
Understand the failure class
Background: "File not found" and ENOENT errors: why libraries can't find a file that should exist — this error's family across 50 libraries.
Related errors
- Problem parsing json contents from file '{filename}': {str(
- Invalid data file URL '{url}'.
- Problem while attempting to access data file URL '{url}': {
- Problem parsing json contents at '{url}': {str(error)}.
AI-assisted analysis of soxoj/maigret@41674631a9 (2026-08-27).
Data as JSON: /api/errors/c8378c6ac58c42fe.
Report an issue: GitHub.