Как отправить большое сообщение api.telegram.org?

Испытываю проблемы с отправкой больших сообщений через телеграм бота. В ходе поиска проблемы отбросил всю лишнюю обвязку и тестировал с помощью curl.

В случае отправки сообщения с текстом размером примерно до 1500, все работает, отправлял вот так:

curl -s -X POST https://api.telegram.org/bot<ТОКЕН>/sendMessage -d chat_id=<ID_ЧАТА> -d text="1100ertyikgnfdhgmcndgbtowewerttysadasdsasadsadddssasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsas"


В случае отправки большого сообщения, работать перестает, в даннос случае отправляю текст размеров 2200 символов:

curl -s -X POST https://api.telegram.org/bot<ТОКЕН>/sendMessage -d chat_id=<ID_ЧАТА> -d text="2200ertyikgnfdhgmcndgbtowewerttysadasdsasadsadddssasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasertyikgnfdhgmcndgbtowewerttysadasdsasadsadddssasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsasasadsas"


Используя ключ -vvvvvv для curl, увидел следующие подробности:
В первом случае (когда сообщение маленькое и отправка срабатывает) вижу:
> Expect: 100-continue
>
< HTTP/1.1 100 Continue
< HTTP/1.1 200 OK


Во втором случае (когда отправляю большое сообщение и отправка не срабатывает) вижу:
> Expect: 100-continue
>
< HTTP/1.1 100 Continue
* Empty reply from server
* Connection #0 to host api.telegram.org left intact
* Closing connection #0


В чем может быть проблема?
  • Вопрос задан
  • 1522 просмотра
Пригласить эксперта
Ответы на вопрос 1
@DEUS9
while len(message) > 0:
                    if len(message) > 4096:
                        part = message[:4096]
                        first_lnbr = part.rfind('\n')
                        if first_lnbr != -1:
                            parts.append(part[:first_lnbr])
                            message = message[first_lnbr:]
                        else:
                            parts.append(part)
                            message = message[4096:]
                    else:
                        parts.append(message)
                        break

                for part in parts:
                    self.bot.send_message(chat_id, part, parse_mode='HTML')
Ответ написан
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Похожие вопросы