Telethon: TypeError: 'ChannelParticipants' object is not subscriptable

Code that causes the issue

    i = 0
    async for user in client.iter_participants(dialog):
        if not user.bot:
            DATA.update(
                {
                    i:{
                        'first_name': user.first_name,
                        'last_name': user.last_name,
                        'username': user.username,
                        'phone': user.phone,
                        'access_hash': user.access_hash,
                        'id': user.id
                    }
                }
            )
            i +=1

Traceback

Traceback (most recent call last):
  File ".\main.py", line 112, in <module>
    client.loop.run_until_complete(main())
  File "D:\python\lib\asyncio\base_events.py", line 616, in run_until_complete
    return future.result()
  File ".\main.py", line 54, in main
    async for user in client.iter_participants(dialog):
  File "D:\python\lib\site-packages\telethon\requestiter.py", line 74, in __anext__
    if await self._load_next_chunk():
  File "D:\python\lib\site-packages\telethon\client\chats.py", line 224, in _load_next_chunk
    participants = results[i]
TypeError: 'ChannelParticipants' object is not subscriptable

As same as 928, @Lonami referenced a solution in comment section which was The issue is fixed in the development version.

The issue appears to be persisting from 2018 until today, and development version seems not useful in this case. any solutions or replacements?

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 1
  • Comments: 24

Commits related to this issue

Most upvoted comments

the quickest solution I figured out: await client.get_participants(group, aggressive=False, limit=limit)

hope it’s helpful.

but it still can’t get all members in a large group, it just make the code free from error

It tries one more time to get members in except handler.

when participants count over 10k, it won’t get all the members

the quickest solution I figured out: await client.get_participants(group, aggressive=False, limit=limit) hope it’s helpful.

What is the value of limit you provides in line 3. I doubt that this code works. As the problem of this issue only happens under some scenarios currently, I believe when groupmembers amount is around 10k, this bug pops out

Value is 200 or less. But it fixes some cases, sometimes you still get the error.

Erm… the problem is I am trying to scrap the member for the entire group with around 10k people. If I set a limit to 200 then how can I get all the member’s data?

Did you figure out how to scrap the members for the entire group with over 10k members? It seems to be possible since it can be displayed in the official client. But I don’t know how to make it.

the quickest solution I figured out: await client.get_participants(group, aggressive=False, limit=limit)

hope it’s helpful.

Thanks, That worked