E
E
enabl32019-03-29 16:54:53
Python
enabl3, 2019-03-29 16:54:53

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)

The error in the logs is the following:
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

2 answer(s)
V
Vladimir, 2019-03-29
@enabl3

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

X
xoo, 2019-03-29
@xoo

The point, it seems to me, is not in python
Take some archive, calculate the hash, send it to the bot, calculate the hash of the received archive, compare

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question