B
B
borisovdenis2017-01-24 20:20:38
Python
borisovdenis, 2017-01-24 20:20:38

How to fix HTTP 413 Request Entity Too Large error (I'm writing telegram bot)?

I'm trying to write a "guess the melody" bot in telegram. I write in Python. Plain text sends without problems, but short .ogg songs cannot be sent. I thought the problem was the file size. Although, this is nonsense, since I read somewhere that the bot can send a file up to 50 mb in size. Well, okay, I reduced the size of the files by 3 times, the files were 300 kb each, now everything is 100 kb each, it still can’t be sent, everything always ends with this error: (__init__.py:250 MainThread) ERROR - TeleBot: "A request to the Telegram API was unsuccessful. The server returned HTTP 413 Request Entity Too Large. Response body:
[b'']"

import os
import time
import config
import telebot

bot = telebot.TeleBot(config.token)

@bot.message_handler(commands=['test'])
def find_file_ids(message):
    for file in os.listdir('music/'):
        if file.split('.')[-1] == 'ogg':
            f = open('music/'+file, 'rb')
            res = bot.send_voice(message.chat.id, f)
            print(file, res)
        time.sleep(3)


if __name__ == '__main__':
    bot.polling(none_stop=True)

Answer the question

In order to leave comments, you need to log in

4 answer(s)
B
borisovdenis, 2017-01-25
@borisovdenis

I seem to have solved the problem. I decided to change the order of the files, and the files started to be sent first with the English name and at the end with the Russian one. And as soon as there is an attempt to send files with a Russian name, an error occurs! I changed the files with Russian names to English ones - everything worked... Very strange...
Someone, also try to send files with Russian names.

S
sim3x, 2017-01-24
@sim3x

https://core.telegram.org/bots/api#senddocument

S
shamanovski, 2017-01-25
@shamanovski

https://github.com/eternnoir/pyTelegramBotAPI/blob...
this library has a send_audio method defined

I
Ilyas, 2017-01-25
@id2669099

i used your code and everything worked for me
though instead of real songs with .ogg format i used a manually created text file, just changed the extension to .ogg
try the same thing, what happens?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question