{"record":{"id":"c7dd3c078c17e2a0","repo":"pypa/pip","slug":"unknown-format-for-r","errorCode":null,"errorMessage":"Unknown format for %r","messagePattern":"Unknown format for %r","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/pip/_vendor/distlib/util.py","lineNumber":1271,"sourceCode":"        check_path(member.linkname, base=link_base)\n\n    dest_dir = os.path.abspath(dest_dir)\n    plen = len(dest_dir)\n    archive = None\n    if format is None:\n        if archive_filename.endswith(('.zip', '.whl')):\n            format = 'zip'\n        elif archive_filename.endswith(('.tar.gz', '.tgz')):\n            format = 'tgz'\n            mode = 'r:gz'\n        elif archive_filename.endswith(('.tar.bz2', '.tbz')):\n            format = 'tbz'\n            mode = 'r:bz2'\n        elif archive_filename.endswith('.tar'):\n            format = 'tar'\n            mode = 'r'\n        else:  # pragma: no cover\n            raise ValueError('Unknown format for %r' % archive_filename)\n    try:\n        if format == 'zip':\n            archive = ZipFile(archive_filename, 'r')\n            if check:\n                names = archive.namelist()\n                for name in names:\n                    check_path(name)\n        else:\n            archive = tarfile.open(archive_filename, mode)\n            if check:\n                for member in archive.getmembers():\n                    check_path(member.name)\n                    check_link(member)\n        if format != 'zip' and sys.version_info[0] < 3:\n            # See Python issue 17153. If the dest path contains Unicode,\n            # tarfile extraction fails on Python 2.x if a member path name\n            # contains non-ASCII characters - it leads to an implicit\n            # bytes -> unicode conversion using ASCII to decode.","sourceCodeStart":1253,"sourceCodeEnd":1289,"githubUrl":"https://github.com/pypa/pip/blob/f399c3718970b1b0e2478dac5296eb62679a9b86/src/pip/_vendor/distlib/util.py#L1253-L1289","documentation":"Raised as ValueError by distlib.util.unarchive when no format was passed (format=None) and the archive filename does not end with any recognized extension: '.zip', '.whl', '.tar.gz', '.tgz', '.tar.bz2', '.tbz', or '.tar'. The function auto-detects format from the extension; an unknown suffix leaves it unable to choose a reader. It is the fallback else-branch (pragma: no cover) of the extension dispatch.","triggerScenarios":"unarchive('archive.xz', '/tmp/out') where '.xz' is unsupported; unarchive('download', '/tmp/out') with no extension; renamed/corrupt archive files whose suffix was stripped. Provide format explicitly to override auto-detection.","commonSituations":"Downloading archives with non-standard extensions; CI caching files under content-hash names with no suffix; user-supplied URLs whose basename lacks a recognized suffix.","solutions":["Pass the format explicitly: unarchive(path, dest, format='zip') or 'tar'/'tgz'/'tbz'.","Rename the file to a recognized extension before calling, or copy to a temp path with a proper suffix.","Validate the extension against ARCHIVE_EXTENSIONS before invoking unarchive."],"exampleFix":"# before\nunarchive('data.xz', '/tmp/out')\n# after\nimport lzma, shutil, tarfile\n# decompress xz first, then:\nunarchive('data.tar', '/tmp/out')","handlingStrategy":"validation","validationCode":"from distlib.util import ARCHIVE_EXTENSIONS\n\ndef detect_format(path):\n    for ext, fmt in [('.zip','zip'),('.whl','zip'),('.tar.gz','tgz'),('.tgz','tgz'),('.tar.bz2','tbz'),('.tbz','tbz'),('.tar','tar')]:\n        if path.endswith(ext):\n            return fmt\n    return None","typeGuard":"def has_known_archive_ext(path: str) -> bool:\n    return isinstance(path, str) and any(path.endswith(e) for e in ARCHIVE_EXTENSIONS)","tryCatchPattern":"try:\n    unarchive(path, dest)\nexcept ValueError as e:\n    if 'Unknown format' in str(e):\n        unarchive(path, dest, format='tar')  # only if you know the real format","preventionTips":["Pass format= explicitly when extension is non-standard.","Rename/copy to a recognized suffix before unarchive."],"tags":["archive","unarchive","distlib","file-format","unsupported-extension"],"backgroundTag":null,"analyzedSha":"f399c3718970b1b0e2478dac5296eb62679a9b86","analyzedAt":"2026-08-08T23:01:42.227Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}