G
G
Gleb Lukashonok2019-09-20 16:58:41
Python
Gleb Lukashonok, 2019-09-20 16:58:41

Why does the error "Bad Request: wrong remote file id specified: Wrong padding in the string" occur?

Good afternoon!
I want to make the telegram bot download the file, work with it and send it ready in response.
This loop works for me 1 time, and gives the following error:

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"}']

Here is the code:
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 delete
        import tableTOtable
        bot.reply_to(message, 'Одну минуточку...')
        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)

Maybe with an interval? Or help how to automatically restart the .py file after the loop. Thank you!

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question