E
E
enabl32019-04-26 00:29:55
Python
enabl3, 2019-04-26 00:29:55

Why does zipfile.is_zipfile(filename) return False?

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 has to unpack it into another folder, and then there are other actions ...
If you just do it through a .py script:

import zipfile
zf = zipfile.is_zipfile('test.zip')
print(zf)

That gives True
But through the bot, for some reason it doesn’t work, in it it looks like this:
if zipfile.is_zipfile('test.zip'):
    bot.send_message(chat_id, "It's a ZIP file")
else:
    bot.send_message(chat_id, "WRONG FILE!!!")

Accordingly, I get "WRONG FILE !!!"

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
enabl3, 2019-05-03
@enabl3

Received the file like this

file_info = bot.get_file(message.document.file_id)
downloaded_file = bot.download_file(file_info.file_path)
src = 'path' + message.document.file_name;
with open(src, 'wb') as new_file:
     new_file.write(downloaded_file)

According to him, and gave an error that this is not an archive. It was decided very trite, at the end it was necessary to add the closing of the file, in my case it is - new_file.close()After which everything works like a clock.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question