【发布时间】:2022-07-09 02:38:29
【问题描述】:
我试图在 python 程序下运行以抓取成员,但是我在下面遇到错误。谁能告诉我代码有什么问题或由于错误?
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>,
这是我的代码,如果有人可以帮助我并告诉我错误原因在哪里,那就太好了
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([用户名,user.id,user.access_hash,name,target_group.title,target_group.id])
print('成员抓取成功。')
【问题讨论】:
-
这是我的 Telethon 版本 >pip show telethon 名称: Telethon 版本:1.23.0 摘要:Python 3 的全功能 Telegram 客户端库 主页:github.com/LonamiWebs/Telethon 作者:Lonami Exo 作者-电子邮件:totufals@hotmail.com 许可证:麻省理工学院 位置:c:\users\loobj\appdata\local\programs\python\python39\lib\site-packages 要求:pyaes、rsa 要求: