I
I
irdaxirdaxirdax2020-08-14 19:31:32
Python
irdaxirdaxirdax, 2020-08-14 19:31:32

'coroutine' object is not iterable telethon?

Hello.
I have a code that simply displays the name of people/channels in dialogs:

from telethon import TelegramClient
api_id = secret
api_hash = "secret"
client = TelegramClient("anon", api_id, api_hash)

client.start()

dlgs = client.get_dialogs()
for dlg in dlgs:
    print(dlg.title)

But when I run the script, I get an error:
Traceback (most recent call last):
  File "C:/Users/User/AppData/Local/Programs/Python/Python38-32/sxasac.py", line 9, in <module>
    for dlg in dlgs:
TypeError: 'coroutine' object is not iterable

If you just output dlgs, then this is displayed:
<coroutine object DialogMethods.get_dialogs at 0x041F22E8>

How can this be fixed?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
S
Sergey Gornostaev, 2020-08-14
@irdaxirdaxirdax

It's easiest to use the synchronous library instead of telethon. Or read the asyncio documentation, learn that asynchronous programs are not written this way. It is also useful to read the documentation of telethon itself, there are many examples.

D
Dr. Bacon, 2020-08-14
@bacon

First we learn the basics of python, then we move on to learning asyncio.

T
Timur Pokrovsky, 2020-08-14
@Makaroshka007

dlgs = await client.get_dialogs()

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question