Limit retries to 500,502,503 errors by default. Developer can also supply what status...
authorJosh Roesslein <jroesslein@gmail.com>
Tue, 13 Oct 2009 23:02:48 +0000 (18:02 -0500)
committerJosh Roesslein <jroesslein@gmail.com>
Tue, 13 Oct 2009 23:02:48 +0000 (18:02 -0500)
tweepy/api.py
tweepy/binder.py

index b56d9fa189708bd5da5929ebdf51d6b16d5d6436..d4020a6fcad42f30953457c3bdd377205d5557a8 100644 (file)
@@ -16,7 +16,7 @@ class API(object):
 
     def __init__(self, auth_handler=None, host='twitter.com', cache=None,
             secure=False, api_root='', validate=True,
-            retry_count=0, retry_delay=0):
+            retry_count=0, retry_delay=0, retry_errors=[500,502,503]):
         # you may access these freely
         self.auth_handler = auth_handler
         self.host = host
@@ -26,6 +26,7 @@ class API(object):
         self.validate = validate
         self.retry_count = retry_count
         self.retry_delay = retry_delay
+        self.retry_errors = retry_errors
 
         # not a good idea to touch these
         self._username = None
index 040a6ef237e793a023521e9a14fadf4232321d06..79865d621aa0291eb04bf97d56a1693da21eea18 100644 (file)
@@ -35,6 +35,7 @@ def bind_api(path, parser, allowed_param=[], method='GET', require_auth=False,
         # check for retry request parameters
         retry_count = kargs.pop('retry_count', api.retry_count)
         retry_delay = kargs.pop('retry_delay', api.retry_delay)
+        retry_errors = kargs.pop('retry_errors', api.retry_errors)
 
         # check for headers
         headers = kargs.pop('headers', {})
@@ -110,8 +111,8 @@ def bind_api(path, parser, allowed_param=[], method='GET', require_auth=False,
             # Get response
             resp = conn.getresponse()
 
-            # If request was successful, quit the loop
-            if resp.status == 200:
+            # Exit request loop if non-retry error code
+            if resp.status not in retry_errors:
                 break
 
             # Sleep before retrying request again