Код: Выделить всё
from telethon import TelegramClient, sync, events
import asyncio
import aiosqlite
api_id = 111111
api_hash = "sksk9449"
client = TelegramClient("main_session", api_id, api_hash)
bot_id = 12345
chat_id = -1234567
async def aiosqlite_connect_db():
return await aiosqlite.connect("DataBase.db")
@client.on(events.NewMessage(chat_id))
async def normal_handler(event):
user_id = event.message.to_dict()['from_id']['user_id']
if user_id == bot_id:
print(True)
client.start()
db = asyncio.run(aiosqlite_connect_db())
client.run_until_disconnected()
Код: Выделить всё
Traceback (most recent call last):
File "/data/user/0/ru.iiec.pydroid3/files/aarch64-linux-android/lib/python3.11/site-packages/telethon/helpers.py", line 430, in get_running_loop
return asyncio.get_running_loop()
^^^^^^^^^^^^^^^^^^^^^^^^^^
RuntimeError: no running event loop
Код: Выделить всё
Traceback (most recent call last):
File "/data/user/0/ru.iiec.pydroid3/files/accomp_files/iiec_run/iiec_run.py", line 31, in
start(fakepyfile,mainpyfile)
File "/data/user/0/ru.iiec.pydroid3/files/accomp_files/iiec_run/iiec_run.py", line 30, in start
exec(open(mainpyfile).read(), __main__.__dict__)
File "", line 27, in
File "/data/user/0/ru.iiec.pydroid3/files/aarch64-linux-android/lib/python3.11/site-packages/telethon/client/updates.py", line 93, in run_until_disconnected
if self.loop.is_running():
^^^^^^^^^
File "/data/user/0/ru.iiec.pydroid3/files/aarch64-linux-android/lib/python3.11/site-packages/telethon/client/telegrambaseclient.py", line 487, in loop
return helpers.get_running_loop()
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/data/user/0/ru.iiec.pydroid3/files/aarch64-linux-android/lib/python3.11/site-packages/telethon/helpers.py", line 432, in get_running_loop
return asyncio.get_event_loop_policy().get_event_loop()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/data/user/0/ru.iiec.pydroid3/files/aarch64-linux-android/lib/python3.11/asyncio/events.py", line 677, in get_event_loop
raise RuntimeError('There is no current event loop in thread %r.'
RuntimeError: There is no current event loop in thread 'MainThread'.
Как я думаю, проблема в asyncio p>
Как мне решить эту проблему? Стоит ли использовать asyncio для запуска асинхронных функций или есть другие способы?
Я пробовал создавать и устанавливать новые потоки, но это не помогло.
Подробнее здесь: https://stackoverflow.com/questions/793 ... d-telethon
Мобильная версия