-
-
Notifications
You must be signed in to change notification settings - Fork 30.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
"tarfile.ReadError: file could not be opened successfully" if compiled without zlib #53224
Comments
When Python is compiled without zlib support, the error message is not very helpful when trying to untar an archive. >>> tarfile.open('sample.tar.gz')
tarfile.ReadError: file could not be opened successfully It happens when you run "python distribute_setup.py", for example. |
Which message do you suggest? |
something like : |
If you pass an explicit mode, the error message is more or less what you want: >>> tarfile.open("uga.tgz", mode="r:gz")
[...]
tarfile.CompressionError: gzip module is not available The way mode="r" detects which compression format is used is to open the file with each open method (i.e. taropen, gzopen, bz2open) until one of them succeeds. If none of them matches it is impossible to say what the reason was. As this would require more than just a simple one-line change, 2.7 is out of the question. But I see what I can do for 3.2. |
Closed after years of inactivity. |
I just ran into this, under Python 3.6. IMHO, the error message should be improved, even when the mode was not passed explicitly. Can someone reopen this? |
How did you install Python? What is your OS? |
It's Python 3.6 from CentOS 6. In my particular case I'm lacking the lzma module. But for figuring that out I had to add the explicit modes to the |
(Sorry: I just noticed the Python 3.6 I'm using is /not/ from distro packages. The issue remains, though, the Python exception could be more descriptive.) |
Hello, I just observed this issue on Python 3.8.2 while running tests for Django project. Example error Traceback (most recent call last):
...
raise ReadError("file could not be opened successfully")
tarfile.ReadError: file could not be opened successfully Python version: 3.8.2 This should be reopened? |
This issue took me a long time to diagnose when attempting to decompress a bzip2-compressed tarball. This occurs with Python 3.9.0. Since I was using asdf, which uses Pyenv internally, to build and manage my Python version, I failed to notice it was missing development libraries. A slightly more informative message could easily have tipped me off to this in short order. |
I took a stab at improving the error message (see the linked PR) $ ./python -c 'import tarfile; tarfile.open("Lib/test/testtar.tar.xz")'
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/home/asottile/workspace/cpython/Lib/tarfile.py", line 1620, in open
raise ReadError(f"file could not be opened successfully:\n{error_msgs}")
tarfile.ReadError: file could not be opened successfully:
- method gz: ReadError('not a gzip file')
- method bz2: CompressionError('bz2 module is not available')
- method xz: CompressionError('lzma module is not available')
- method tar: ReadError('truncated header') |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: