Friday, September 9, 2022

Error Telethon - TypeError: 'ChannelParticipants' object is not subscriptable

When you are trying to export members of a Telegram public group using python script and you get following error

Traceback (most recent call last):
  File "t1_exportgroup.py", line 49, in <module>
    all_participants = client.get_participants(target_group, aggressive=False)
  File "/home/user/virtualenvs/telegram/lib/python3.8/site-packages/telethon/requestiter.py", line 74, in __anext__
    if await self._load_next_chunk():
  File "/home/user/virtualenvs/telegram/lib/python3.8/site-packages/telethon/client/chats.py", line 223, in _load_next_chunk
    participants = results[i]
TypeError: 'ChannelParticipants' object is not subscriptable

Solution :

You are getting this error because group has more than 5k or 6K members, you need to provide limit in your python script.

all_participants = []
all_participants = client.get_participants(target_group, aggressive=False, limit=5000)

Now try again, you should be able to export members less than 5000.

 Watch the video to see the demo :