{"record":{"id":"23765d56b6de4bec","repo":"django/django","slug":"couldn-t-extract-file-s-to-s-s","errorCode":null,"errorMessage":"couldn't extract file %s to %s: %s","messagePattern":"couldn't extract file (.+?) to (.+?): (.+?)","errorType":"console","errorClass":"CommandError","httpStatus":null,"severity":"error","filePath":"django/core/management/templates.py","lineNumber":380,"sourceCode":"            ext = base[-4:] + ext\n            base = base[:-4]\n        return base, ext\n\n    def extract(self, filename):\n        \"\"\"\n        Extract the given file to a temporary directory and return\n        the path of the directory with the extracted content.\n        \"\"\"\n        prefix = \"django_%s_template_\" % self.app_or_project\n        tempdir = tempfile.mkdtemp(prefix=prefix, suffix=\"_extract\")\n        self.paths_to_remove.append(tempdir)\n        if self.verbosity >= 2:\n            self.stdout.write(\"Extracting %s\" % filename)\n        try:\n            archive.extract(filename, tempdir)\n            return tempdir\n        except (archive.ArchiveException, OSError) as e:\n            raise CommandError(\n                \"couldn't extract file %s to %s: %s\" % (filename, tempdir, e)\n            )\n\n    def is_url(self, template):\n        \"\"\"Return True if the name looks like a URL.\"\"\"\n        if \":\" not in template:\n            return False\n        scheme = template.split(\":\", 1)[0].lower()\n        return scheme in self.url_schemes\n\n    def apply_umask(self, old_path, new_path):\n        current_umask = os.umask(0)\n        os.umask(current_umask)\n        current_mode = stat.S_IMODE(os.stat(old_path).st_mode)\n        os.chmod(new_path, current_mode & ~current_umask)\n\n    def make_writeable(self, filename):\n        \"\"\"","sourceCodeStart":362,"sourceCodeEnd":398,"githubUrl":"https://github.com/django/django/blob/ae25a40be07e8a749edf526df37c93e59d4a22c9/django/core/management/templates.py#L362-L398","documentation":"A CommandError raised by TemplateCommand.extract when `django.utils.archive.extract(filename, tempdir)` raises ArchiveException or OSError. The downloaded/copied file is not a recognized, well-formed archive (zip, tar, tar.gz, etc.).","triggerScenarios":"Passing `--template=notes.txt` (plain file, not an archive), a truncated/corrupted .zip from an interrupted download, or an archive type not supported by django.utils.archive.","commonSituations":"Pointing --template at a single template file instead of an archive, GitHub 'raw' URLs that return HTML, partial downloads, or .rar/.7z archives (unsupported).","solutions":["Confirm the file is a real archive: `file template.zip` should report Zip or gzip/tar data.","Re-download the template (the file may be truncated).","Repackage as .zip or .tar.gz, which django.utils.archive supports.","If you only have a directory of templates, point --template at the directory path directly (handle_template returns dirs without extracting)."],"exampleFix":"# before\ndjango-admin startproject myproj --template=https://example.com/readme.md\n# after\ndjango-admin startproject myproj --template=https://example.com/template.zip","handlingStrategy":"validation","validationCode":"import zipfile, tarfile\n\ndef looks_like_archive(path: str) -> bool:\n    try:\n        if zipfile.is_zipfile(path):\n            return True\n        if tarfile.is_tarfile(path):\n            return True\n    except OSError:\n        pass\n    return False","typeGuard":null,"tryCatchPattern":"from django.core.management.base import CommandError\ntry:\n    call_command('startproject', name, template=path)\nexcept CommandError as e:\n    if 'couldn't extract' in str(e):\n        logger.error('Template %s is not a valid zip/tar archive', path)\n        sys.exit(1)\n    raise","preventionTips":["Verify `file <template>` reports Zip/gzip data before pointing --template at it.","Repackage .rar/.7z templates as .zip before use.","Point --template at a directory if you only have loose template files."],"tags":["django","scaffolding","archive","extraction","zip","tar"],"analyzedSha":"ae25a40be07e8a749edf526df37c93e59d4a22c9","analyzedAt":"2026-08-06T21:46:51.801Z","schemaVersion":2},"datasetVersion":"2026-08-07T03:17:09.362Z"}