Answer the question
In order to leave comments, you need to log in
Why doesn't unzip work correctly when called from python with subprocess.Popen?
Hello everyone, I've run into this problem.
There is a bot to which I send a ZIP archive, it saves it on my computer, and then it must unpack it into another folder, and then there are other actions ... For this, there is a bash script, when executed from the console, the whole thing works successfully (the archive is unpacked without errors and everything is OK).
But through the bot, for some reason this script does not work, from python the whole thing looks like this:
proc = subprocess.Popen('test.sh', stdout=subprocess.PIPE)
output = proc.stdout.read()
result = output
bot.send_message(message.chat.id, result)
End-of-central-directory signature not found. Either this file is not
a zipfile, or it constitutes one disk of a multi-part archive. In the
latter case the central directory and zipfile comment will be found on
the last disk(s) of this archive.
unzip: cannot find zipfile directory in one of (путь к архиву), period.
Answer the question
In order to leave comments, you need to log in
Why make unzipping external when you can code elegantly?
import zipfile
zip_ref = zipfile.ZipFile(path_to_zip_file, 'r')
zip_ref.extractall(directory_to_extract_to)
zip_ref.close()
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question