Skip to content

Instantly share code, notes, and snippets.

@Birdi7
Created July 18, 2023 12:35
Show Gist options
  • Save Birdi7/1fb722d9491d2471ba28c99faff4f265 to your computer and use it in GitHub Desktop.
Save Birdi7/1fb722d9491d2471ba28c99faff4f265 to your computer and use it in GitHub Desktop.
from asgiref.sync import async_to_sync
bot = Bot('ABC')
async_to_sync(bot.send_message)(
chat_id='123', text='abc
)
File "/Users/.../Projects/.../.venv/lib/python3.10/site-packages/celery/app/trace.py", line 451, in trace_task
R = retval = fun(*args, **kwargs)
File "/Users/.../Projects/.../.venv/lib/python3.10/site-packages/celery/app/trace.py", line 734, in __protected_call__
return self.run(*args, **kwargs)
File "/Users/.../Projects/.../.venv/lib/python3.10/site-packages/celery/app/autoretry.py", line 34, in run
return task._orig_run(*args, **kwargs)
File "/Users/.../Projects/.../.../.../tasks/communication.py", line 114, in send_communication
result = sender.send(user, message, communication=communication)
File "/Users/.../Projects/.../.../.../utils/messages/senders.py", line 308, in send
async_to_sync(self.bot.send_message)(chat_id=user.telegram_id,
File "/Users/.../Projects/.../.venv/lib/python3.10/site-packages/asgiref/sync.py", line 277, in __call__
return call_result.result()
File "/Users/.../.pyenv/versions/3.10.12/lib/python3.10/concurrent/futures/_base.py", line 451, in result
return self.__get_result()
File "/Users/.../.pyenv/versions/3.10.12/lib/python3.10/concurrent/futures/_base.py", line 403, in __get_result
raise self._exception
File "/Users/.../Projects/.../.venv/lib/python3.10/site-packages/asgiref/sync.py", line 353, in main_wrap
result = await self.awaitable(*args, **kwargs)
File "/Users/.../Projects/.../.venv/lib/python3.10/site-packages/aiogram/client/bot.py", line 2596, in send_message
return await self(call, request_timeout=request_timeout)
File "/Users/.../Projects/.../.venv/lib/python3.10/site-packages/aiogram/client/bot.py", line 374, in __call__
return await self.session(self, method, timeout=request_timeout)
File "/Users/.../Projects/.../.venv/lib/python3.10/site-packages/aiogram/client/session/base.py", line 194, in __call__
return cast(TelegramType, await middleware(bot, method))
File "/Users/.../Projects/.../.venv/lib/python3.10/site-packages/aiogram/client/session/aiohttp.py", line 153, in make_request
async with session.post(
File "/Users/.../Projects/.../.venv/lib/python3.10/site-packages/aiohttp/client.py", line 1141, in __aenter__
self._resp = await self._coro
File "/Users/.../Projects/.../.venv/lib/python3.10/site-packages/aiohttp/client.py", line 448, in _request
handle = tm.start()
File "/Users/.../Projects/.../.venv/lib/python3.10/site-packages/aiohttp/helpers.py", line 652, in start
return self._loop.call_at(when, self.__call__)
File "/Users/.../.pyenv/versions/3.10.12/lib/python3.10/asyncio/base_events.py", line 732, in call_at
self._check_closed()
File "/Users/.../.pyenv/versions/3.10.12/lib/python3.10/asyncio/base_events.py", line 515, in _check_closed
raise RuntimeError('Event loop is closed')
RuntimeError: Event loop is closed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment