From 0508cd111051a266e4b5588ca77213ffae3eafc0 Mon Sep 17 00:00:00 2001
From: Bryan Tong Minh <bryan.tongminh@gmail.com>
Date: Wed, 20 Aug 2008 19:37:26 +0000
Subject: [PATCH] Handle being throttled

---
 mwclient/client.py | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/mwclient/client.py b/mwclient/client.py
index 55278b5..b6ccc6f 100644
--- a/mwclient/client.py
+++ b/mwclient/client.py
@@ -268,9 +268,15 @@ class Site(object):
 			self.conn.cookies[self.host].update(cookies)
 			
 		if self.credentials:
-			login = self.api('login', lgname = self.credentials[0], lgpassword = self.credentials[1])
-			if login['login']['result'] != 'Success':
-				raise errors.LoginError(self, login['login'])
+			wait_token = self.wait_token()
+			while True:
+				login = self.api('login', lgname = self.credentials[0], lgpassword = self.credentials[1])
+				if login['login']['result'] == 'Success':
+					break
+				elif login['login']['result'] == 'Throttled':
+					self.wait(wait_token, login['login']['wait'])
+				else:
+					raise errors.LoginError(self, login['login'])
 				
 		if self.initialized:				
 			info = self.api('query', meta = 'userinfo', uiprop = 'groups|rights')
-- 
GitLab