From ac62f7f2444d898fa4f14faa684ae12bc219b2c1 Mon Sep 17 00:00:00 2001 From: drevicko Date: Sun, 28 Apr 2013 18:33:22 +1000 Subject: [PATCH] added timeout to api constructor with default 60s, set timeout when creating HTTPConnection and HTTPSConnection in binder.py modified: tweepy/api.py modified: tweepy/binder.py --- tweepy/api.py | 3 ++- tweepy/binder.py | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/tweepy/api.py b/tweepy/api.py index 1eaaf91..3924652 100644 --- a/tweepy/api.py +++ b/tweepy/api.py @@ -17,7 +17,7 @@ class API(object): def __init__(self, auth_handler=None, host='api.twitter.com', search_host='search.twitter.com', cache=None, secure=True, api_root='/1.1', search_root='', - retry_count=0, retry_delay=0, retry_errors=None, + retry_count=0, retry_delay=0, retry_errors=None, timeout=60, parser=None): self.auth = auth_handler self.host = host @@ -29,6 +29,7 @@ class API(object): self.retry_count = retry_count self.retry_delay = retry_delay self.retry_errors = retry_errors + self.timeout = timeout self.parser = parser or ModelParser() """ statuses/home_timeline """ diff --git a/tweepy/binder.py b/tweepy/binder.py index 7817537..528021d 100644 --- a/tweepy/binder.py +++ b/tweepy/binder.py @@ -130,9 +130,9 @@ def bind_api(**config): # Open connection # FIXME: add timeout if self.api.secure: - conn = httplib.HTTPSConnection(self.host) + conn = httplib.HTTPSConnection(self.host,timeout=self.api.timeout) else: - conn = httplib.HTTPConnection(self.host) + conn = httplib.HTTPConnection(self.host,timeout=self.api.timeout) # Apply authentication if self.api.auth: -- 2.25.1