[Python] A request to the Telegram API was unsuccessful. Error code: 400. Description: Bad...

Discussão em 'Python' iniciado por Stack, Outubro 6, 2024.

  1. Stack

    Stack Membro Participativo

    An error occurs when sending a video of a large weight: A request to the Telegram API was unsuccessful. Error code: 400. Description: Bad Request: file is too big

    import telebot

    bot = telebot.TeleBot('xxxxxx')
    chat_id= xxxxx

    @bot.message_handler(commands=['start'])
    def start(message):
    mess = f'text'
    bot.send_message(message.chat.id, mess, parse_mode='html' )


    @bot.message_handler(content_types=['photo'])
    def handle_photo(message):
    photo = message.photo[-1]
    file_info = bot.get_file(photo.file_id)
    downloaded_file = bot.download_file(file_info.file_path)
    save_path = 'photo.jpg'
    with open(save_path, 'wb') as new_file:
    new_file.write(downloaded_file)
    bot.reply_to(message, 'text')
    bot.send_photo(chat_id=chat_id, photo=downloaded_file, caption=message.caption)

    @bot.message_handler(content_types=['video'])
    def get_file(message):
    file_info = bot.get_file(message.video.file_id)
    file_content = bot.download_file(file_info.file_path)
    bot.reply_to(message, 'text')
    bot.send_video(chat_id=chat_id, video=file_content, caption=message.caption)

    bot.polling(none_stop=True)

    Continue reading...

Compartilhe esta Página