[Python] tarfile.ReadError: file could not be opened successfully

Discussão em 'Python' iniciado por Stack, Março 27, 2025.

  1. Stack

    Stack Membro Participativo

    I have the following piece of code to open a .tgz file, but I'm getting tarfile.ReadError: file could not be opened successfully.

    fp = tarfile.open('file.tgz', 'r')
    print fp.list()
    fp.close()


    I can extract this archive using "tar -xvzf file.tgz." Apparently it has something to do with the way the file was created because when I compare two different .tgz files using file, I see a difference; file2.tgz works with this piece of code.

    $ file file.tgz
    file.tgz: gzip compressed data, from FAT filesystem (MS-DOS, OS/2, NT)

    $ file file2.tgz
    file2.tgz: gzip compressed data, was "", last modified: Tue Aug 19 11:16:10 2014, max compression


    Any ideas why this is happening or how I can modify file.tgz so that it works with tarfile?

    Note: I'm using Python 2.7.5.

    Continue reading...

Compartilhe esta Página