AUTOMATIC1111/stable-diffusion-webui · warning · ValueError
File cannot be fetched: {filename}. Extensions allowed: {all
Error message
File cannot be fetched: {filename}. Extensions allowed: {allowed_preview_extensions()}. What it means
Third guard in fetch_file(): after the file exists and sits in an allowed directory, its extension (splittext lowercased, dot stripped) must be in allowed_preview_extensions(). Preview-serving is intentionally limited to image types, so anything else (.txt, .json, .webp depending on settings) is refused.
Source
Thrown at modules/ui_extra_networks.py:108
"""registers extra networks page for the UI; recommend doing it in on_before_ui() callback for extensions"""
extra_pages.append(page)
allowed_dirs.clear()
allowed_dirs.update(set(sum([x.allowed_directories_for_previews() for x in extra_pages], [])))
def fetch_file(filename: str = ""):
from starlette.responses import FileResponse
if not os.path.isfile(filename):
raise HTTPException(status_code=404, detail="File not found")
if not any(Path(x).absolute() in Path(filename).absolute().parents for x in allowed_dirs):
raise ValueError(f"File cannot be fetched: {filename}. Must be in one of directories registered by extra pages.")
ext = os.path.splitext(filename)[1].lower()[1:]
if ext not in allowed_preview_extensions():
raise ValueError(f"File cannot be fetched: {filename}. Extensions allowed: {allowed_preview_extensions()}.")
# would profit from returning 304
return FileResponse(filename, headers={"Accept-Ranges": "bytes"})
def fetch_cover_images(page: str = "", item: str = "", index: int = 0):
from starlette.responses import Response
page = next(iter([x for x in extra_pages if x.name == page]), None)
if page is None:
raise HTTPException(status_code=404, detail="File not found")
metadata = page.metadata.get(item)
if metadata is None:
raise HTTPException(status_code=404, detail="File not found")
cover_images = json.loads(metadata.get('ssmd_cover_images', {}))
image = cover_images[index] if index < len(cover_images) else None
View on GitHub (pinned to 82a973c043)
Solutions
- Rename the preview to a standard extension: .png, .jpg, or .webp
- Check Settings for preview/extension allowlist options and reload the UI after changing them
- Confirm the real extension with `ls`/file manager — hidden double extensions are the usual culprit
Defensive patterns
Strategy: validation
Validate before calling
from modules import ui_extra_networks
def ext_allowed(filename):
return os.path.splitext(filename)[1].lower()[1:] in ui_extra_networks.allowed_preview_extensions() Prevention
- Save previews only as png/jpg/webp
- Check 'show hidden file extensions' to catch double extensions
- Keep metadata about preview paths consistent with actual files
When it happens
Trigger: Requesting a preview whose extension is not in the allowed set — commonly because the user's Settings > 'Preview image extension' or the built-in allowlist (png/jpg/jpeg/webp as configured) excludes the file they linked, e.g. .avif or extensionless files.
Common situations: Users dropping arbitrary files next to models expecting them to be served as previews; browser/OS hiding extensions causing a 'photo.png' that is really 'photo.png.txt'.
Related errors
- File cannot be fetched: {filename}. Must be in one of direct
- Sampler not found
- Invalid encoded image
- always on script {alwayson_script_name} not found
- Cannot have a selectable script in the always on scripts par
AI-assisted analysis of AUTOMATIC1111/stable-diffusion-webui@82a973c043 (2026-08-14).
Data as JSON: /api/errors/007870820efccca9.
Report an issue: GitHub.