From: Josh Roesslein Date: Tue, 13 Oct 2009 23:02:48 +0000 (-0500) Subject: Limit retries to 500,502,503 errors by default. Developer can also supply what status... X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=c7837b0e8b752402eeaa879e7e757b16083b363c;p=tweepy.git Limit retries to 500,502,503 errors by default. Developer can also supply what status codes to retry on. --- diff --git a/tweepy/api.py b/tweepy/api.py index b56d9fa..d4020a6 100644 --- a/tweepy/api.py +++ b/tweepy/api.py @@ -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 diff --git a/tweepy/binder.py b/tweepy/binder.py index 040a6ef..79865d6 100644 --- a/tweepy/binder.py +++ b/tweepy/binder.py @@ -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