Skip to content
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

Closed
florentx mannequin opened this issue Jun 11, 2010 · 13 comments
Closed

"tarfile.ReadError: file could not be opened successfully" if compiled without zlib #53224

florentx mannequin opened this issue Jun 11, 2010 · 13 comments
Assignees
Labels
3.9 only security fixes stdlib Python modules in the Lib dir type-crash A hard crash of the interpreter, possibly with a core dump

Comments

@florentx
Copy link
Mannequin

florentx mannequin commented Jun 11, 2010

BPO 8978
Nosy @gustaebel, @merwok, @florentx, @asottile, @miss-islington, @krf, @ProProgrammer, @jwillikers
PRs
  • bpo-8978: improve tarfile.open error message when lzma / bz2 are missing #24850
  • 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:

    assignee = 'https://github.com/gustaebel'
    closed_at = <Date 2016-04-21.05:25:39.462>
    created_at = <Date 2010-06-11.21:48:52.113>
    labels = ['library', '3.9', 'type-crash']
    title = '"tarfile.ReadError: file could not be opened successfully" if compiled without zlib'
    updated_at = <Date 2021-04-27.20:54:24.157>
    user = 'https://github.com/florentx'

    bugs.python.org fields:

    activity = <Date 2021-04-27.20:54:24.157>
    actor = 'vstinner'
    assignee = 'lars.gustaebel'
    closed = True
    closed_date = <Date 2016-04-21.05:25:39.462>
    closer = 'lars.gustaebel'
    components = ['Library (Lib)']
    creation = <Date 2010-06-11.21:48:52.113>
    creator = 'flox'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 8978
    keywords = []
    message_count = 13.0
    messages = ['107587', '107589', '107592', '107643', '263880', '330408', '330411', '330413', '330415', '365153', '380322', '388791', '392111']
    nosy_count = 8.0
    nosy_names = ['lars.gustaebel', 'eric.araujo', 'flox', 'Anthony Sottile', 'miss-islington', 'kfunk', 'Deep Sukhwani', 'jwillikers']
    pr_nums = ['24850']
    priority = 'low'
    resolution = 'works for me'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'crash'
    url = 'https://bugs.python.org/issue8978'
    versions = ['Python 3.9']

    @florentx
    Copy link
    Mannequin Author

    florentx mannequin commented Jun 11, 2010

    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.
    ( http://s3.pixane.com/pip_distribute.png )

    @florentx florentx mannequin added extension-modules C modules in the Modules dir type-bug An unexpected behavior, bug, or error labels Jun 11, 2010
    @vstinner
    Copy link
    Member

    Which message do you suggest?

    @florentx
    Copy link
    Mannequin Author

    florentx mannequin commented Jun 11, 2010

    something like :
    raise CompressionError("zlib module is not available")

    @florentx florentx mannequin added stdlib Python modules in the Lib dir and removed extension-modules C modules in the Modules dir labels Jun 11, 2010
    @gustaebel
    Copy link
    Mannequin

    gustaebel mannequin commented Jun 12, 2010

    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.

    @gustaebel
    Copy link
    Mannequin

    gustaebel mannequin commented Apr 21, 2016

    Closed after years of inactivity.

    @gustaebel gustaebel mannequin closed this as completed Apr 21, 2016
    @krf
    Copy link
    Mannequin

    krf mannequin commented Nov 26, 2018

    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?

    @vstinner
    Copy link
    Member

    I just ran into this, under Python 3.6.

    How did you install Python? What is your OS?

    @krf
    Copy link
    Mannequin

    krf mannequin commented Nov 26, 2018

    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 tarfile.open calls in my Python script.

    @krf
    Copy link
    Mannequin

    krf mannequin commented Nov 26, 2018

    (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.)

    @proprogrammer
    Copy link
    Mannequin

    proprogrammer mannequin commented Mar 27, 2020

    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?

    @jwillikers
    Copy link
    Mannequin

    jwillikers mannequin commented Nov 4, 2020

    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.

    @jwillikers jwillikers mannequin added 3.9 only security fixes type-crash A hard crash of the interpreter, possibly with a core dump and removed type-bug An unexpected behavior, bug, or error labels Nov 4, 2020
    @asottile
    Copy link
    Mannequin

    asottile mannequin commented Mar 16, 2021

    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')

    @miss-islington
    Copy link
    Contributor

    New changeset 9aea31d by Anthony Sottile in branch 'master':
    bpo-8978: improve tarfile.open error message when lzma / bz2 are missing (GH-24850)
    9aea31d

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.9 only security fixes stdlib Python modules in the Lib dir type-crash A hard crash of the interpreter, possibly with a core dump
    Projects
    None yet
    Development

    No branches or pull requests

    2 participants