3

Хочу сделать что бы телеграм-бот скачивал файл, работал с ним и отправлял в ответ готовый. Этот цикл у меня работает 1 раз, и выдает следующую ошибку:

A request to the Telegram API was unsuccessful. The server returned HTTP 400 Bad Request. Response body: [b'{"ok":false,"error_code":400,"description":"Bad Request: wrong remote file id specified: Wrong padding in the string"}']

Я так понимаю что проблема с файл_ид, но т.к. я учусь всего неделю - не могу разобраться. Вот код:

import telebot
import constant
bot = telebot.TeleBot(constant.API_TOKEN)

# Сохраняем присланый от пользователя файл
@bot.message_handler(content_types=['document'])
def handle_file(message):
    try:
        chat_id = message.chat.id
        file_info = bot.get_file(message.document.file_id)
        downloaded_file = bot.download_file(file_info.file_path)
        src = u'D:\\Python\\Bot\\' + message.document.file_name
        with open(src, 'wb') as new_file:
            new_file.write(downloaded_file)
        import tableTOtable   # Запускается обработчик файла
        doc = open('D:\\Python\\Bot\\Счет-фактура.pdf', 'rb')
        bot.send_document(chat_id, doc)
        bot.send_document(chat_id, "FILEID")
    except Exception as e:
        bot.reply_to(message, e)
        import kill_procces     # Закрывается процесс эксэля
        import delete      # Удаляется больше не нужный файл
bot.polling(none_stop=True, interval=0)

1 ответ 1

1
def welcome(message):
    with open('./files/file.txt', 'rb') as f1:
        bot.send_document(message.chat.id, f1)

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge you have read our privacy policy.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.