Visitar URL original
Client.iter_chat_members() errors out on ChatParticipantsForbidden · Issue #498 · pyrogram/pyrogram · GitHub
The Wayback Machine - https://web.archive.org/web/20201210054308/https://github.com/pyrogram/pyrogram/issues/498
Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Client.iter_chat_members() errors out on ChatParticipantsForbidden #498

Open
JosXa opened this issue Sep 29, 2020 · 4 comments
Open

Client.iter_chat_members() errors out on ChatParticipantsForbidden #498

JosXa opened this issue Sep 29, 2020 · 4 comments

Comments

@JosXa
Copy link
Contributor

@JosXa JosXa commented Sep 29, 2020

Using a straightforward client.iter_chat_members(...) may raise the following stack trace:

> File "C:/projects/josxabot/app/tools\search.py", line 30, in main
    async for member in client.iter_chat_members(d.chat.id):
              │         │      │                 │ │    └ -477484124
              │         │      │                 │ └ pyrogram.types.Chat(id=-477484124, type='group', is_creator=True, title='E-Commerce Telegram Bot', members_count=0)
              │         │      │                 └ pyrogram.types.Dialog(chat=pyrogram.types.Chat(id=-477484124, type='group', is_creator=True, title='E-Commerce Telegram Bot',...
              │         │      └ <function IterChatMembers.iter_chat_members at 0x0000022690D48820>
              │         └ <app.clients.telegram.userclients.UserClient object at 0x000002268E5C4250>
              └ pyrogram.types.ChatMember(user=pyrogram.types.User(id=679615554, is_self=False, is_contact=False, is_mutual_contact=False, is...

  File "C:\Users\INT002327\AppData\Local\pypoetry\Cache\virtualenvs\josxabot-c3BmTbt9-py3.8\lib\site-packages\pyrogram\methods\chats\iter_chat_members.py", line 109, in iter_chat_members
    chat_members = await self.get_chat_members(
                         │    └ <function GetChatMembers.get_chat_members at 0x0000022690D45160>
                         └ <app.clients.telegram.userclients.UserClient object at 0x000002268E5C4250>

  File "C:\Users\INT002327\AppData\Local\pypoetry\Cache\virtualenvs\josxabot-c3BmTbt9-py3.8\lib\site-packages\pyrogram\methods\chats\get_chat_members.py", line 115, in get_chat_members
    members = r.full_chat.participants.participants
              │ └ <member 'full_chat' of 'ChatFull' objects>
              └ pyrogram.raw.types.messages.ChatFull(full_chat=pyrogram.raw.types.ChatFull(id=477484124, about='', participants=pyrogram.raw....

AttributeError: 'ChatParticipantsForbidden' object has no attribute 'participants'
@delivrance
Copy link
Member

@delivrance delivrance commented Oct 1, 2020

The issue is you are unable to get the members list in that chat, not sure what pyrogram should do in that case, re-raise another error?

@JosXa
Copy link
Contributor Author

@JosXa JosXa commented Oct 2, 2020

Ah, that's what it's about, I see. Sure, If I was confused then certainly I'm not alone --> raise new from with nicer message would be awesome

@lorien
Copy link

@lorien lorien commented Oct 7, 2020

The issue is that pyrogram throws AtributeError which is bad design. To catch this exception user have to except AttributeError as ex and then analyze str(ex) for has no attribute 'participants' string. The better solution would be throwing custom exception like OhSnapYouHaveNoChatAccess (or something like that) that could be catch directly.

@delivrance
Copy link
Member

@delivrance delivrance commented Oct 23, 2020

Of course, the reason that exception was raised is simply because Pyrogram didn't know a better way to handle it. I'd appreciate an example with steps to reproduce the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants
You can’t perform that action at this time.