skip to Main Content

I’ve got following error while trying to send a message to a specific telegram channel:

TimedOut: Timed out
The read operation timed out

the method which I used from python-telegram-bot was send_message.

Although my bot got this error but it still sent the message to the channel and because I did not catch that exception all data from the message was lost but I really need to remove my messages from that channel after a specific period of time.

Is this OK that the bot sent the message even though it got Timed Out? How can I prevent this from happen again or remove this kind of messages from the channel after being sent?

2

Answers


  1. Time out errors mean that TG didn’t send a response to your send_message request quick enough. It does not necessarily mean that the request wasn’t processed – that’s why the message may still be sent. However, without response from TG, you don’t have the message id of the resulting message and it will be hard to impossible to delete it.

    You can try to increase the time that PTB waits for a response from TG. THis can be done in different ways:

    • with the timeout parameter of send_message
    • with Defaults.timeout, if you’re using PTBs Defaults setup
    • by specifying it via the request_kwargs that you pass to Updater

    You may want to have a look at this wiki page on networking.


    Disclaimer: I’m currently the maintainer of python-telegram-bot

    Login or Signup to reply.
  2. After a couple of hours reading here and there, and passing timeout=30 to context.bot.send_audio and getting an error that says unknown parameter even though send_audio‘s docs clearly states it takes a timeout param, I found that you can fix this by passing the timeouts to the Application upon building it:

    application = ApplicationBuilder()
        .token(bot_data["token"])
        .read_timeout(30)
        .write_timeout(30)
        .build()
    

    This fixed my bot. Hope this helps you as well.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search