【问题标题】:'telegram.error.TimedOut: Timed out' problem\'telegram.error.TimedOut: Timed out\' 问题
【发布时间】:2023-02-09 19:50:59
【问题描述】:

我的电报机器人程序遇到了问题。当我启动它时,几秒钟后出现此错误。它与我的互联网连接有关吗?还是代码错了?

代码:

from telegram.ext import *
def start_command(update, context):
    update.massage.reply_text("Hi. I'm a test bot")

def help_command(update, context):
    update.massage.reply_text("if you need help! search on Google")

def main():
    app = Application.builder().token('your token').build()
    
    app.add_handler(CommandHandler("start", start_command))
    app.add_handler(CommandHandler("help", help_command))
   
    app.run_polling()
    app.idle()

if __name__ == '__main__':
    main()

错误:

  File "C:\Users\AppData\Local\Programs\Python\Python311\Lib\site-packages\telegram\request\_httpxrequest.py", line 200, in do_request
    raise TimedOut from err
telegram.error.TimedOut: Timed out

【问题讨论】:

标签: telegram-bot python-telegram-bot


【解决方案1】:

尝试这个:

def main():
  app = Application.builder().token('your token').read_timeout(30).write_timeout(30).build()

  app.add_handler(CommandHandler("start", start_command))
  app.add_handler(CommandHandler("help", help_command))

  app.run_polling()
  app.idle()

if __name__ == '__main__':
   main()

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-02-03
    • 2012-01-20
    • 2019-06-17
    • 2015-09-11
    • 2021-12-06
    • 2013-05-01
    • 2017-03-22
    • 1970-01-01
    相关资源
    最近更新 更多