U
U
usiting2021-11-28 19:36:21
Python
usiting, 2021-11-28 19:36:21

Decrypts QRcode in TelegramBotAPI, but decodes photo characteristics?

There is a code snippet:

#bot decrypting a qrcode            
@bot.message_handler(commands=['decrypt'])
def decrypting(message):
    bot.send_message(message.chat.id, 'Пришли мне фото с QRкодом и я расшифрую его')
    @bot.message_handler(content_types=['photo'])
    def decrypting(message):
        print('message.photo =', message.photo)
        fileID = message.photo[-1].file_id
        print('fileID =', fileID)
        file_info = bot.get_file(fileID)
        print('file.file_path =', file_info.file_path)
        downloaded_file = bot.download_file(file_info.file_path)

        with open("qr_decrypting.jpg", 'wb') as new_file:
            new_file.write(downloaded_file)

        data = decode(Image.open('qr_decrypting.jpg'))

        bot.send_message(message.chat.id, f'QRкод: \n\n{data}')
        os.remove('qr_decrypting.jpg')


The function works, but displays the message:
61a3afdbc7a38150965788.jpeg
Why is this happening?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
shurshur, 2021-11-28
@usiting

Obviously, because data is an instance of the Decoded class. I think you need data.data, and even cast bytes to a string: data.data.decode()

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question