2022-02-18

Scraping users from Telegram failed

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:\Users\loobj\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Python 3.9\scrape.py", line 49, in <module>
    all_participants = client.get_participants(target_group, aggressive=True)
  File "C:\Users\loobj\AppData\Local\Programs\Python\Python39\lib\site-packages\telethon\sync.py", line 39, in syncified
    return loop.run_until_complete(coro)
  File "C:\Users\loobj\AppData\Local\Programs\Python\Python39\lib\asyncio\base_events.py", line 642, in run_until_complete
    return future.result()
  File "C:\Users\loobj\AppData\Local\Programs\Python\Python39\lib\site-packages\telethon\client\chats.py", line 503, in get_participants
    return await self.iter_participants(*args, **kwargs).collect()
  File "C:\Users\loobj\AppData\Local\Programs\Python\Python39\lib\site-packages\telethon\requestiter.py", line 113, in collect
    async for message in self:
  File "C:\Users\loobj\AppData\Local\Programs\Python\Python39\lib\site-packages\telethon\requestiter.py", line 74, in __anext__
    if await self._load_next_chunk():
  File "C:\Users\loobj\AppData\Local\Programs\Python\Python39\lib\site-packages\telethon\client\chats.py", line 221, in _load_next_chunk
    results = await self.client(self.requests)
  File "C:\Users\loobj\AppData\Local\Programs\Python\Python39\lib\site-packages\telethon\client\users.py", line 30, in __call__
    return await self._call(self._sender, request, ordered=ordered)
  File "C:\Users\loobj\AppData\Local\Programs\Python\Python39\lib\site-packages\telethon\client\users.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.')



from Recent Questions - Stack Overflow https://ift.tt/ktLFBqg
https://ift.tt/O5oIAD6

No comments:

Post a Comment