aboutsummaryrefslogtreecommitdiffstats
path: root/python-tornado/unassembled/Platform.py
diff options
context:
space:
mode:
Diffstat (limited to 'python-tornado/unassembled/Platform.py')
-rw-r--r--python-tornado/unassembled/Platform.py16
1 files changed, 10 insertions, 6 deletions
diff --git a/python-tornado/unassembled/Platform.py b/python-tornado/unassembled/Platform.py
index 871a400..b0e0be9 100644
--- a/python-tornado/unassembled/Platform.py
+++ b/python-tornado/unassembled/Platform.py
@@ -51,7 +51,8 @@ class Pubnub(PubnubCoreAsync):
self.http = tornado.httpclient.AsyncHTTPClient(max_clients=1000)
self.id = None
- def _request(self, request, callback=None, error=None, single=False):
+ def _request(self, request, callback=None, error=None,
+ single=False, read_timeout=5, connect_timeout=5):
def _invoke(func, data):
if func is not None:
@@ -61,8 +62,8 @@ class Pubnub(PubnubCoreAsync):
request = tornado.httpclient.HTTPRequest(
url, 'GET',
self.headers,
- connect_timeout=10,
- request_timeout=310)
+ connect_timeout=connect_timeout,
+ request_timeout=read_timeout)
if single is True:
id = time.time()
self.id = id
@@ -76,20 +77,23 @@ class Pubnub(PubnubCoreAsync):
if body is None:
return
- #print(body)
def handle_exc(*args):
return True
if response.error is not None:
with ExceptionStackContext(handle_exc):
- response.rethrow()
+ if response.code in [403, 401]:
+ response.rethrow()
+ else:
+ _invoke(error, {"message": response.reason})
return
+
try:
data = json.loads(body)
except TypeError as e:
try:
data = json.loads(body.decode("utf-8"))
- except:
+ except ValueError as ve:
_invoke(error, {'error': 'json decode error'})
if 'error' in data and 'status' in data and 'status' != 200: