will
will

Reputation: 21

Python Tar file could not be opened successfully

ReadError at / file could not be opened successfully

"ReadError('not a bzip2 file',)"

This error, "file could not be opened successfully" is extremely strange as not one or two days ago this was working just today it is not and i cannot figure out why.

def main(sqldump_dict):
    print 'in main'
    import os
    import re
    count_aim = int(str(sqldump_dict["name"]).count(".gz"))
    count_aim += int(str(sqldump_dict["name"]).count(".tar"))
    count = 0

    sqldump_dict["sql_name"] = sqldump_dict["name"]
    old_tar_path = ""
    old_tar_name = ""
    gz_list = int(str(sqldump_dict["name"]).count(".gz"))
    tar_list = int(str(sqldump_dict["name"]).count(".tar"))
    while(count != count_aim):
        if count > 0:

            print str(os.path.join(sqldump_dict["path"] + old_tar_path))
            tar = tarfile.open(str(os.path.join(sqldump_dict["path"] + old_tar_path)))
            tar.extractall(path=sqldump_dict["path"] + old_tar_path.replace(old_tar_name, ""))
            tar.close()
        else:
            tar = tarfile.open(str(os.path.join(sqldump_dict["path"] + sqldump_dict["name"])))
            tar.extractall(path=sqldump_dict["path"])

            tar.close()

            pat = re.compile(r'([^/]*)$')

            old_tar_path = str(tar.members[0].path).replace("/", "\\")
            pat_find = pat.findall(str(tar.members[0].path))
            old_tar_name =  str(pat_find[0])

Upvotes: 2

Views: 1916

Answers (1)

jmunsch
jmunsch

Reputation: 24119

I also received the following error:

ReadError('not a bzip2 file',)

This worked for me python2.7:

sudo apt-get install python-dev
sudo pip install backports.lzma

Upvotes: 0

Related Questions