{"record":{"id":"6089430a6265dcd2","repo":"pypa/pip","slug":"cannot-determine-archive-format-of-location","errorCode":null,"errorMessage":"Cannot determine archive format of {location}","messagePattern":"Cannot determine archive format of (.+?)","errorType":"exception","errorClass":"InstallationError","httpStatus":null,"severity":"error","filePath":"src/pip/_internal/utils/unpacking.py","lineNumber":407,"sourceCode":"\n    # avoid ambiguous case where both signature checks return True\n    is_zipfile = zipfile.is_zipfile(filename)\n    is_tarfile = tarfile.is_tarfile(filename)\n    if is_zipfile and not is_tarfile:\n        return _unzip()\n    if is_tarfile and not is_zipfile:\n        return _untar()\n    if is_zipfile and is_tarfile:\n        logger.error(\"Ambiguous file signature in %s.\", filename)\n\n    logger.critical(\n        \"Cannot unpack file %s (downloaded from %s, content-type: %s); \"\n        \"cannot detect archive format\",\n        filename,\n        location,\n        content_type,\n    )\n    raise InstallationError(f\"Cannot determine archive format of {location}\")\n","sourceCodeStart":389,"sourceCodeEnd":408,"githubUrl":"https://github.com/pypa/pip/blob/f399c3718970b1b0e2478dac5296eb62679a9b86/src/pip/_internal/utils/unpacking.py#L389-L408","documentation":"Raised by unpack_file() when pip cannot determine the archive format of a downloaded file. Format detection tries the HTTP content-type header, then the filename extension, then the file's magic signature (zip vs tar), and if all fail or are ambiguous, this error is raised. It indicates the downloaded artifact is not a recognizable zip or tar archive.","triggerScenarios":"Calling unpack_file() with a file whose content-type is not application/zip or application/x-gzip, whose extension is not a known archive extension, and whose magic bytes are neither unambiguously zip nor tar — or where both magic checks return true (ambiguous).","commonSituations":"A download URL returned an HTML error page (e.g. 404 page) instead of the archive. A corrupted or truncated download. A package URL pointing to a raw .py file or a directory. A proxy or CDN mangling the content-type. An archive in an unsupported format (e.g. .rar, .7z).","solutions":["Manually download the URL and inspect the file: 'file <downloaded>' and 'head -c 100 <downloaded> | xxd'","Verify the URL is correct and points to a .whl, .tar.gz, .zip, or .tar.bz2/xz artifact","Check for an HTML error page (404/403) returned instead of the archive","Clear pip's cache with 'pip cache purge' and retry to eliminate a corrupt cached download","If behind a proxy, verify it is not stripping or altering the content-type header"],"exampleFix":"// before\npip install https://example.com/mypackage\n// after\n# verify the URL resolves to a real archive\ncurl -sIL https://example.com/mypackage-1.0.tar.gz | grep -i content-type\n# point at a concrete wheel or sdist filename\npip install https://example.com/mypackage-1.0-py3-none-any.whl","handlingStrategy":"validation","validationCode":"import zipfile, tarfile, os\n\ndef is_unpackable_archive(path: str) -> bool:\n    if not os.path.isfile(path):\n        return False\n    if zipfile.is_zipfile(path):\n        return True\n    try:\n        return tarfile.is_tarfile(path)\n    except Exception:\n        return False\n\n# before unpacking\nif not is_unpackable_archive(filename):\n    raise ValueError(f'{filename} is not a recognized zip or tar archive')","typeGuard":"import zipfile, tarfile\n\ndef is_valid_archive(path: str) -> bool:\n    is_zip = zipfile.is_zipfile(path)\n    is_tar = False\n    try:\n        is_tar = tarfile.is_tarfile(path)\n    except Exception:\n        pass\n    return (is_zip and not is_tar) or (is_tar and not is_zip)","tryCatchPattern":"from pip._internal.exceptions import InstallationError\n\ntry:\n    unpack_file(filename, location)\nexcept InstallationError as e:\n    if 'Cannot determine archive format' in str(e):\n        # re-download or fix the URL\n        os.remove(filename)\n        raise DownloadError(f'downloaded file is not a valid archive: {e}')\n    raise","preventionTips":["Verify download URLs point to concrete .whl/.tar.gz/.zip files","Check for HTML error pages by inspecting downloads with 'file <downloaded>'","Clear pip cache ('pip cache purge') if a download may be corrupt","Use HTTPS URLs from the official PyPI index"],"tags":["archive","download","unpacking","installation","format-detection"],"backgroundTag":null,"analyzedSha":"f399c3718970b1b0e2478dac5296eb62679a9b86","analyzedAt":"2026-08-08T23:01:42.227Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}