RuntimeWarning: сопрограмма 'main' никогда не ожидала ошибки - PullRequest
1 голос
/ 21 января 2020

Я запускаю этот тестовый код:

import telethon.sync
from telethon import TelegramClient 
from telethon.tl.functions.messages import AddChatUserRequest 
from telethon.tl.functions.contacts import ImportContactsRequest 

api_id = XXXXXXX
api_hash = 'XXXXXXXXXXXXXXC'

with TelegramClient('anon', api_id, api_hash) as client:
async def main():

client(AddChatUserRequest(-XXXXXXXXXXXXXX, ['username'], fwd_limit=10))
main()

И он дает мне это:

/data/data/ru.iiec.pydroid3/files/temp_iiec_codefile.py:19: RuntimeWarning: coroutine 'main' was never awaited
main()
RuntimeWarning: Enable tracemalloc to get the object allocation traceback

Что я должен сделать, чтобы программа работала?

1 Ответ

2 голосов
/ 21 января 2020

Посмотрите документацию telethon, посмотрите, как начинается событие l oop:

from telethon import TelegramClient


api_id = 12345
api_hash = '0123456789abcdef0123456789abcdef'
client = TelegramClient('anon', api_id, api_hash)


async def main():
    me = await client.get_me()
    # etc.


with client:
    client.loop.run_until_complete(main())
...