From 2a9da075486480adffd6042403c4b11425737f75 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Tue, 20 Feb 2018 17:00:25 +0100 Subject: [PATCH] Catch FloodWaits when calling GetContacts --- pyrogram/client/client.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/pyrogram/client/client.py b/pyrogram/client/client.py index 2548998c..80deb580 100644 --- a/pyrogram/client/client.py +++ b/pyrogram/client/client.py @@ -2351,7 +2351,14 @@ class Client: ) def get_contacts(self, _hash: int = 0): - contacts = self.send(functions.contacts.GetContacts(_hash)) - self.fetch_peers(contacts.users) - - return contacts + while True: + try: + contacts = self.send(functions.contacts.GetContacts(_hash)) + except FloodWait as e: + log.info("Get contacts flood wait: {}".format(e.x)) + time.sleep(e.x) + continue + else: + log.info("Contacts count: {}".format(len(contacts.users))) + self.fetch_peers(contacts.users) + return contacts