【发布时间】:2022-01-05 15:22:56
【问题描述】:
我正在创建一个可以生成和解密二维码的电报机器人。我使用 BytesIO 实现了二维码的创建:
#bot creating a qrcode
@bot.message_handler(commands=['create'])
def creating_qr(message):
bot.send_message(message.chat.id, 'Enter text and ill generate QRcode')
@bot.message_handler(content_types=['text'])
def creating_qr(message):
qr_img = qrcode.make(message.text)
bio = BytesIO()
qr_img.save(bio, 'JPEG')
bio.seek(0)
bot.send_photo(message.chat.id, bio)
我尝试使用相同的方法解密 qrcode,但 ApiTelegramBot 文档说 photo 是一个列表,因此我无法将其保存在 BytesIO 中。如何保存photo然后解密?
我尝试过的方法:
def decrypting(message):
detector = cv2.QRCodeDetector()
qr_image = message.photo
bio = BytesIO()
qr_image.save(bio, 'JPEG')
bio.seek(0)
data = detector.detectAndDecode(bio)
bot.send_message(message.chat.id, f'QR code data: \n\n{data}')
【问题讨论】:
-
嗨 Valeriy,欢迎来到 stackoverflow!你不应该把编程语言之类的东西放在标题中,而是使用标签(就像你所做的那样)。
标签: python api qr-code py-telegram-bot-api