This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Title: "tarfile.ReadError: file could not be opened successfully" if compiled without zlib
Type: crash Stage: resolved
Components: Library (Lib) Versions: Python 3.9
Status: closed Resolution: works for me
Dependencies: Superseder:
Assigned To: lars.gustaebel Nosy List: Anthony Sottile, Deep Sukhwani, eric.araujo, flox, jwillikers, kfunk, lars.gustaebel, miss-islington
Priority: low Keywords:

Created on 2010-06-11 21:48 by flox, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 24850 merged Anthony Sottile, 2021-03-13 22:05
Messages (13)
msg107587 - (view) Author: Florent Xicluna (flox) * (Python committer) Date: 2010-06-11 21:48
When Python is compiled without zlib support, the error message is not very helpful when trying to untar an archive.

tarfile.ReadError: file could not be opened successfully

It happens when you run "python", for example.
 ( )
msg107589 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2010-06-11 21:53
Which message do you suggest?
msg107592 - (view) Author: Florent Xicluna (flox) * (Python committer) Date: 2010-06-11 22:00
something like :
  raise CompressionError("zlib module is not available")
msg107643 - (view) Author: Lars Gustäbel (lars.gustaebel) * (Python committer) Date: 2010-06-12 10:33
If you pass an explicit mode, the error message is more or less what you want:

>>>"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.
msg263880 - (view) Author: Lars Gustäbel (lars.gustaebel) * (Python committer) Date: 2016-04-21 05:25
Closed after years of inactivity.
msg330408 - (view) Author: Kevin Funk (kfunk) Date: 2018-11-26 10:10
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?
msg330411 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2018-11-26 10:16
> I just ran into this, under Python 3.6.

How did you install Python? What is your OS?
msg330413 - (view) Author: Kevin Funk (kfunk) Date: 2018-11-26 10:24
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 `` calls in my Python script.
msg330415 - (view) Author: Kevin Funk (kfunk) Date: 2018-11-26 10:35
(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.)
msg365153 - (view) Author: Deep Sukhwani (Deep Sukhwani) Date: 2020-03-27 14:19
Hello, I just observed this issue on Python 3.8.2 while running tests for Django project.

Example error
ERROR: test_extract_function (utils_tests.test_archive.TestArchive) [foobar.tar.xz]
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
OS: macOS Catalina 10.15.4

This should be reopened?
msg380322 - (view) Author: Jordan Williams (jwillikers) Date: 2020-11-04 13:47
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.
msg388791 - (view) Author: Anthony Sottile (Anthony Sottile) * Date: 2021-03-16 00:05
I took a stab at improving the error message (see the linked PR)

$ ./python -c 'import tarfile;"Lib/test/testtar.tar.xz")'
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/home/asottile/workspace/cpython/Lib/", 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')
msg392111 - (view) Author: miss-islington (miss-islington) Date: 2021-04-27 17:39
New changeset 9aea31deddf7458be3546f72185740f3cd06687f by Anthony Sottile in branch 'master':
bpo-8978: improve error message when lzma / bz2 are missing (GH-24850)
Date User Action Args
2022-04-11 14:57:02adminsetgithub: 53224
2021-04-27 20:54:24vstinnersetnosy: - vstinner
2021-04-27 17:39:07miss-islingtonsetnosy: + miss-islington
messages: + msg392111
2021-03-16 00:05:55Anthony Sottilesetmessages: + msg388791
2021-03-13 22:05:16Anthony Sottilesetnosy: + Anthony Sottile

pull_requests: + pull_request23611
2020-11-04 13:47:47jwillikerssetversions: + Python 3.9, - Python 3.3
nosy: + jwillikers

messages: + msg380322

type: behavior -> crash
2020-03-27 14:19:55Deep Sukhwanisetnosy: + Deep Sukhwani
messages: + msg365153
2018-11-26 10:35:32kfunksetmessages: + msg330415
2018-11-26 10:24:16kfunksetmessages: + msg330413
2018-11-26 10:16:17vstinnersetmessages: + msg330411
2018-11-26 10:10:01kfunksetnosy: + kfunk
messages: + msg330408
2016-04-21 05:25:39lars.gustaebelsetstatus: open -> closed
resolution: works for me
messages: + msg263880

stage: resolved
2011-02-08 13:03:48eric.araujosetnosy: + eric.araujo

versions: + Python 3.3, - Python 3.2
2010-06-12 10:33:10lars.gustaebelsetmessages: + msg107643
versions: - Python 2.7
2010-06-11 22:03:07floxsetnosy: lars.gustaebel, vstinner, flox
components: + Library (Lib), - Extension Modules
2010-06-11 22:00:17floxsetmessages: + msg107592
2010-06-11 21:55:23pitrousetassignee: lars.gustaebel

nosy: + lars.gustaebel
2010-06-11 21:53:15vstinnersetnosy: + vstinner
messages: + msg107589
2010-06-11 21:48:52floxcreate