all Python 3tarfileexception
tarfile.TarError
exceptions
The base exception of the tarfile module: it catches ReadError, CompressionError, StreamError, ExtractError, HeaderError and FilterError.
Syntax
except tarfile.TarError:
It inherits from Exception directly, not from OSError: disk errors during extraction (no space, no permission) arrive as separate OSErrors, and except tarfile.TarError will not catch them. The reverse is also true: except OSError lets a broken archive through. For robust handling, catch both.
Examples
import tarfile
for name in ('ReadError', 'StreamError', 'FilterError'):
print(issubclass(getattr(tarfile, name), tarfile.TarError))
# → True / True / True
print(issubclass(tarfile.TarError, OSError)) # → False
See also
Common errors
Open in the full glossarydocs.python.orgReport an inaccuracy