ZhuLinsen/daily_stock_analysis · warning · HTTPException
invalid_import_file
invalid_import_file
Error message
invalid_import_file
What it means
400 with error code 'invalid_import_file' raised when service.import_env() raises ConfigImportError, meaning the submitted backup content is not a parseable .env file (structure problem), as opposed to semantic validation failures which raise ConfigValidationError. The detail message comes from exc.message, which states exactly what could not be parsed.
Source
Thrown at api/v1/endpoints/system_config.py:501
request_obj: Request,
service: SystemConfigService = Depends(get_system_config_service),
) -> UpdateSystemConfigResponse:
"""Import a `.env` backup into the active config."""
try:
_allow_env_backup_access(request_obj)
except EnvBackupAccessDenied as exc:
logger.warning("System config import blocked: %s", exc)
_raise_env_backup_access_error(exc)
try:
payload = service.import_env(
config_version=request.config_version,
content=request.content,
reload_now=request.reload_now,
)
return UpdateSystemConfigResponse.model_validate(payload)
except ConfigImportError as exc:
raise HTTPException(
status_code=400,
detail={
"error": "invalid_import_file",
"message": exc.message,
},
)
except ConfigValidationError as exc:
raise HTTPException(
status_code=400,
detail={
"error": "validation_failed",
"message": "System configuration validation failed",
"issues": exc.issues,
},
)
except ConfigConflictError as exc:
raise HTTPException(
status_code=409,View on GitHub (pinned to 5159bd72e8)
Solutions
- Read the 'message' field in the 400 detail — it names the specific parse problem and usually the offending line.
- Validate the file locally: every non-comment line must be KEY=VALUE with balanced quotes; strip any BOM.
- Re-export a fresh backup from the source instance and import that unmodified file to confirm the pipeline works.
- If editing is required, use a plain-text editor and keep UTF-8 without BOM.
Example fix
# before (broken): line without '=' OPENAI_API_KEY sk-xxxx # after OPENAI_API_KEY=sk-xxxx
Defensive patterns
Strategy: validation
Validate before calling
def looks_like_env(content: str) -> bool:
if content.startswith('\ufeff'):
return False # BOM
for i, line in enumerate(content.splitlines(), 1):
s = line.strip()
if not s or s.startswith('#'):
continue
if '=' not in s:
return False
return True
assert looks_like_env(request_content), 'not a parseable .env payload' Try / catch
resp = client.post('/config/import', json=body)
if resp.status_code == 400 and resp.json()['detail']['error'] == 'invalid_import_file':
show(resp.json()['detail']['message']) # names the offending line; fix content, don't retry blind Prevention
- Import only files produced by /config/export, unmodified.
- If editing is needed, keep UTF-8 without BOM and KEY=VALUE on every active line.
- Run a local dotenv parser (python-dotenv) over the content before uploading.
When it happens
Trigger: POST /api/v1/system/config/config/import with request.content that is malformed .env syntax: missing '=' in a line, invalid quoting, BOM/UTF-16 encoding from a Windows editor, truncated file, or JSON accidentally pasted instead of .env text.
Common situations: Importing a backup edited by hand; uploading the wrong file (report JSON, YAML config) to the import dialog; backups saved with Excel or Notepad that added a BOM or CRLF-only corruption; partial file transfer.
Related errors
AI-assisted analysis of ZhuLinsen/daily_stock_analysis@5159bd72e8 (2026-08-15).
Data as JSON: /api/errors/96401cde50435be3.
Report an issue: GitHub.