Forums

Python - AsyncTeleBot polling timeout error

Running this python script in a bash console:

import asyncio
from telebot.async_telebot import AsyncTeleBot
bot = AsyncTeleBot(SECRET_TOKEN)
asyncio.run(bot.infinity_polling())

This error message is printed to the console repeatedly every 2 seconds, regardless of the timeout parameter.

(async_telebot.py:321 MainThread) ERROR - TeleBot: "Request timeout. Request: method=get url=getUpdates params=<aiohttp.formdata.FormData object at 0x7f0c35d9b7f0> files=None request_timeout=20"

The same script works well when run locally, or if I used TeleBot instead of AsyncTeleBot (I need it to be asyncronous)

I have tried the following, but still facing the same issue

  • setting timeout and request_timeout parameters
  • using bot.polling(non_stop=True)
  • updating pyTelegramBotAPI

Would appreciate any assistance in resolving this issue!

Updating pyTelegramBotAPI to 4.8.0 resulted in a similar error:

2022-12-14 17:11:34,999 (asyncio_helper.py:101 MainThread) ERROR - TeleBot: "Aiohttp ClientError: ClientConnectorError"
2022-12-14 17:11:34,999 (async_telebot.py:361 MainThread) ERROR - TeleBot: "Infinity polling exception: Request timeout. Request: method=get url=getMe params=<aiohttp.formdata.FormData object at 0x7f003abe6520> files=None request_timeout=300"
2022-12-14 17:11:35,000 (async_telebot.py:363 MainThread) ERROR - TeleBot: "Exception traceback:
Traceback (most recent call last):
  File "/home/sinstarzs/.local/lib/python3.9/site-packages/telebot/async_telebot.py", line 357, in infinity_polling
    await self._process_polling(non_stop=True, timeout=timeout, request_timeout=request_timeout,
  File "/home/sinstarzs/.local/lib/python3.9/site-packages/telebot/async_telebot.py", line 397, in _process_polling
    self._user = await self.get_me()
  File "/home/sinstarzs/.local/lib/python3.9/site-packages/telebot/async_telebot.py", line 1899, in get_me
    result = await asyncio_helper.get_me(self.token)
  File "/home/sinstarzs/.local/lib/python3.9/site-packages/telebot/asyncio_helper.py", line 154, in get_me
    return await _process_request(token, method_url)
  File "/home/sinstarzs/.local/lib/python3.9/site-packages/telebot/asyncio_helper.py", line 105, in _process_request
    raise RequestTimeout("Request timeout. Request: method={0} url={1} params={2} files={3} request_timeout={4}".format(method, url, params, files, request_timeout, current_try))
telebot.asyncio_helper.RequestTimeout: Request timeout. Request: method=get url=getMe params=<aiohttp.formdata.FormData object at 0x7f003abe6520> files=None request_timeout=300

Is it possible that your code requires specific configuration to use proxy? See https://help.pythonanywhere.com/pages/403ForbiddenError/#proxy-details

Telegram API is whitelisted, and this script works when I run with Telebot instead of AsyncTeleBot

That's why I'm suggesting checking proxy settings. Free accounts connect to whitelisted sites via proxy.

It works after adding this. Thanks!

from telebot import asyncio_helper
asyncio_helper.proxy = 'http://proxy.server:3128'

Excellent, thanks for confirming!