Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Telegram notification error when log entry is > 4096 chars

See original GitHub issue

Describe the bug When using the telegram notifier, if the log message is too long for a Telegram text message (> 4096 characters) a NotificationError with the message Notification errors: Bad Request: message is too long is raised.

To Reproduce

import logging

from notifiers.logging import NotificationHandler

message = "-" * 4097

    format="%(asctime)s - %(levelname)s - %(message)s")
defaults = {"token": bot_token, "chat_id": chat_id}
notification_handler = NotificationHandler("telegram", defaults=defaults)


Expected behavior Maybe the notification handler should split the log entry into parts each <= 4096 characters long. Then it can send the parts.

Additional context Python version: 3.8.10 OS: Windows 7 64-Bit

I don’t use the Telegram notifier (get_notifier("telegram")), but I also tried sending the same long message and instead of an exception being raised, the call ended successfully and no actual message was sent to the chat ID. But maybe another issue should be opened for that.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

liiightcommented, Feb 9, 2022

@allerter I given this some thought and research and I don’t think this issue should be handled by notifiers. I just supply a logger which redirects the logs to a provider, the responsibility for how to handle/cut the content should belong to the client. That being said, I limited the msg size for telegram to 4096 in #404, so now you would get a validation error and the message will not be sent

a5r0ncommented, Aug 15, 2021

any updates?

i suggest to add some config to notifer, maybe split_long=True, and send_as_file=True?

i can put some PR for this

Read more comments on GitHub >

github_iconTop Results From Across the Web

Telegram notifications are not sent when longer than 4096 chars
A simple fix would be to split the message once it reaches 4096 characters (preferably when there is a newline before the 4096...
Read more >
Telegram Notifications Not Working? [2022 Pro Fixes] - AirDroid
If you have issues with Telegram notifications not working as they ... Step 3: Tap on Log Out in the right-side menu of...
Read more >
BadHTTPResponse(response.status, text, response) telegram ...
@CBroe I test the question code with sending 4096 a character as text.It works fine so i Think the problem is with persian...
Read more >
pm2-telegram - NPM Package Overview -
combine short messages to one message (the resultant big message shorter than 4096 characters) to avoid impact of Telegram messages frequency ...
Read more >
telegram-send - PyPI
There is a maximum message length of 4096 characters, larger messages will be automatically split up into smaller ones and sent separately. To...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Post

No results found

github_iconTop Related Hashnode Post

No results found