skip to Main Content

I trying to run below python program to scrape the member however i encounter error below.can anyone pls advise what wrong with code or due to bug?

 Traceback (most recent call last):
  File "C:UsersloobjAppDataRoamingMicrosoftWindowsStart MenuProgramsPython 3.9scrape.py", line 49, in <module>
    all_participants = client.get_participants(target_group, aggressive=True)
  File "C:UsersloobjAppDataLocalProgramsPythonPython39libsite-packagestelethonsync.py", line 39, in syncified
    return loop.run_until_complete(coro)
  File "C:UsersloobjAppDataLocalProgramsPythonPython39libasynciobase_events.py", line 642, in run_until_complete
    return future.result()
  File "C:UsersloobjAppDataLocalProgramsPythonPython39libsite-packagestelethonclientchats.py", line 503, in get_participants
    return await self.iter_participants(*args, **kwargs).collect()
  File "C:UsersloobjAppDataLocalProgramsPythonPython39libsite-packagestelethonrequestiter.py", line 113, in collect
    async for message in self:
  File "C:UsersloobjAppDataLocalProgramsPythonPython39libsite-packagestelethonrequestiter.py", line 74, in __anext__
    if await self._load_next_chunk():
  File "C:UsersloobjAppDataLocalProgramsPythonPython39libsite-packagestelethonclientchats.py", line 221, in _load_next_chunk
    results = await self.client(self.requests)
  File "C:UsersloobjAppDataLocalProgramsPythonPython39libsite-packagestelethonclientusers.py", line 30, in __call__
    return await self._call(self._sender, request, ordered=ordered)
  File "C:UsersloobjAppDataLocalProgramsPythonPython39libsite-packagestelethonclientusers.py", line 75, in _call
    raise MultiError(exceptions, results, requests)
telethon.errors.common.MultiError: ([None, FloodWaitError('A wait of 31 seconds is required (caused by GetParticipantsRequest)'), None, None, FloodWaitError('A wait of 31 seconds is required (caused by GetParticipantsRequest)'), FloodWaitError('A wait of 31 seconds is required (caused by GetParticipantsRequest)'), FloodWaitError('A wait of 31 seconds is required (caused by GetParticipantsRequest)'), FloodWaitError('A wait of 31 seconds is required (caused by GetParticipantsRequest)'), FloodWaitError('A wait of 31 seconds is required (caused by GetParticipantsRequest)'), FloodWaitError('A wait of 31 seconds is required (caused by GetParticipantsRequest)'), FloodWaitError('A wait of 31 seconds is required (caused by GetParticipantsRequest)'), FloodWaitError('A wait of 31 seconds is required (caused by GetParticipantsRequest)'), FloodWaitError('A wait of 31 seconds is required (caused by GetParticipantsRequest)'), FloodWaitError('A wait of 31 seconds is required (caused by GetParticipantsRequest)'), FloodWaitError('A wait of 31 seconds is required (caused by GetParticipantsRequest)'), FloodWaitError('A wait of 31 seconds is required (caused by GetParticipantsRequest)'), FloodWaitError('A wait of 31 seconds is required (caused by GetParticipantsRequest)'), FloodWaitError('A wait of 31 seconds is required (caused by GetParticipantsRequest)'), FloodWaitError('A wait of 31 seconds is required (caused by GetParticipantsRequest)'), FloodWaitError('A wait of 31 seconds is required (caused by GetParticipantsRequest)'), FloodWaitError('A wait of 31 seconds is required (caused by GetParticipantsRequest)'), FloodWaitError('A wait of 31 seconds is required (caused by GetParticipantsRequest)'), FloodWaitError('A wait of 31 seconds is required (caused by GetParticipantsRequest)'), FloodWaitError('A wait of 31 seconds is required (caused by GetParticipantsRequest)')], [<telethon.tl.types.channels.ChannelParticipants object at 0x0000029681BAE280>, None, <telethon.tl.types.channels.ChannelParticipants object at 0x0000029681B94BB0>, <telethon.tl.types.channels.ChannelParticipants object at 0x0000029681BAE4C0>, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None], [<telethon.tl.functions.channels.GetParticipantsRequest object at 0x0000029681B7CDC0>, <telethon.tl.functions.channels.GetParticipantsRequest object at 0x0000029681B7CE80>, <telethon.tl.functions.channels.GetParticipantsRequest object at 0x0000029681B7CF40>, <telethon.tl.functions.channels.GetParticipantsRequest object at 0x0000029681B80040>, <telethon.tl.functions.channels.GetParticipantsRequest object at 0x0000029681B80100>, <telethon.tl.functions.channels.GetParticipantsRequest object at 0x0000029681B801C0>, <telethon.tl.functions.channels.GetParticipantsRequest object at 0x0000029681B80280>, <telethon.tl.functions.channels.GetParticipantsRequest object at 0x0000029681B80340>, <telethon.tl.functions.channels.GetParticipantsRequest object at 0x0000029681B80400>, <telethon.tl.functions.channels.GetParticipantsRequest object at 0x0000029681B804C0>, 

here is my code and would be very nice if someone could help me out and show me where was the error cause

     client.connect()
        if not client.is_user_authorized():
            client.send_code_request(phone)
            client.sign_in(phone, input('Enter the code: '))
        
        chats = []
        last_date = None
        chunk_size = 200
        groups=[]
         
        result = client(GetDialogsRequest(
                     offset_date=last_date,
                     offset_id=0,
                     offset_peer=InputPeerEmpty(),
                     limit=chunk_size,
                     hash = 0
                 ))
        chats.extend(result.chats)
         
        for chat in chats:
            try:
                if chat.megagroup== True:
                    groups.append(chat)
            except:
                continue
        print('Choose a group to scrape members from:')
        i=0
        for g in groups:
            print(str(i) + '- ' + g.title)
            i+=1
        g_index = input("Enter a Number: ")
        target_group=groups[int(g_index)]
         
        print('Fetching Members...')
        all_participants = []
        all_participants = client.get_participants(target_group, aggressive=True)
        print('Saving In file...')
        with open("members.csv","w",encoding='UTF-8') as f:
            writer = csv.writer(f,delimiter=",",lineterminator="n")
            writer.writerow(['username','user id', 'access hash','name','group', 'group id'])
            for user in all_participants:
                if user.username:
                    username= user.username
                else:
                    username= ""
                if user.first_name:
                    first_name= user.first_name
                else:
                    first_name= ""
                if user.last_name:
                    last_name= user.last_name
                else:
                    last_name= ""
                name= (first_name + ' ' + last_name).strip()

writer.writerow([username,user.id,user.access_hash,name,target_group.title, target_group.id])
print(‘Members scraped successfully.’)

3

Answers


  1. The function GetParticipantsRequest is breaking/terminating before 31 secs. If you can increase the time somehow like using the sleep method from the time library that will work too.

    Login or Signup to reply.
  2. try changing

    all_participants = client.get_participants(target_group, aggressive=True)

    to

    all_participants = client.get_participants(target_group, aggressive=False)

    Login or Signup to reply.
  3. Try this –

    await client.get_participants(group, aggressive=False, limit=2000)
    

    Setting limit to 2000 worked for me, you can try increasing it.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search