From e7139bb0a0d93b965e55e5c7735099ff343f209c Mon Sep 17 00:00:00 2001 From: Josh Roesslein Date: Wed, 14 Oct 2009 12:30:36 -0500 Subject: [PATCH] Fix favorites methods. Retry request when enabled by defaults will retry on any non-200 error. If retry_errors list is supplied it will then only retry when those status codes are returned by twitter. --- tweepy/api.py | 32 +++++++++++++++++--------------- tweepy/binder.py | 6 ++++-- 2 files changed, 21 insertions(+), 17 deletions(-) diff --git a/tweepy/api.py b/tweepy/api.py index a0d73fa..c5c917d 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_errors=[500,502,503]): + retry_count=0, retry_delay=0, retry_errors=None): # you may access these freely self.auth_handler = auth_handler self.host = host @@ -692,13 +692,14 @@ class API(object): http://apiwiki.twitter.com/Twitter-REST-API-Method%3A-favorites%C2%A0create """ - create_favorite = bind_api( - path = '/favorites/create.json', - method = 'POST', - parser = parse_status, - allowed_param = ['id'], - require_auth = True - ) + def create_favorite(self, id): + return bind_api( + path = '/favorites/create/%s.json' % id, + method = 'POST', + parser = parse_status, + allowed_param = ['id'], + require_auth = True + )(self, id) """ favorites/destroy @@ -710,13 +711,14 @@ class API(object): http://apiwiki.twitter.com/Twitter-REST-API-Method%3A-favorites%C2%A0destroy """ - destroy_favorite = bind_api( - path = '/favorites/destroy.json', - method = 'DELETE', - parser = parse_status, - allowed_param = ['id'], - require_auth = True - ) + def destroy_favorite(self, id): + return bind_api( + path = '/favorites/destroy/%s.json' % id, + method = 'DELETE', + parser = parse_status, + allowed_param = ['id'], + require_auth = True + )(self, id) """ notifications/follow diff --git a/tweepy/binder.py b/tweepy/binder.py index 79865d6..9097d75 100644 --- a/tweepy/binder.py +++ b/tweepy/binder.py @@ -112,8 +112,10 @@ def bind_api(path, parser, allowed_param=[], method='GET', require_auth=False, resp = conn.getresponse() # Exit request loop if non-retry error code - if resp.status not in retry_errors: - break + if retry_errors is None: + if resp.status == 200: break + else: + if resp.status not in retry_errors: break # Sleep before retrying request again time.sleep(retry_delay) -- 2.25.1