diff options
| author | Devendra | 2014-04-24 00:16:57 +0530 |
|---|---|---|
| committer | Devendra | 2014-04-24 00:16:57 +0530 |
| commit | 493e29a108255eb3ae3166dc920f40e2f4e5c4c4 (patch) | |
| tree | bce73bc6014e0b10820ebc1393515f7e3e521b88 /python/unassembled/Platform.py | |
| parent | f7b89bfafae34fa22509c1d1c59d1284ec62c5df (diff) | |
| download | pubnub-python-493e29a108255eb3ae3166dc920f40e2f4e5c4c4.tar.bz2 | |
adding single file for all platforms
Diffstat (limited to 'python/unassembled/Platform.py')
| -rw-r--r-- | python/unassembled/Platform.py | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/python/unassembled/Platform.py b/python/unassembled/Platform.py index 83bb6f5..17180fa 100644 --- a/python/unassembled/Platform.py +++ b/python/unassembled/Platform.py @@ -1,6 +1,6 @@ try: import urllib.request -except: +except ImportError: import urllib2 import threading @@ -58,20 +58,24 @@ class HTTPClient: else: if latest_sub_callback['callback'] is not None: latest_sub_callback['id'] = 0 + print data try: data = json.loads(data) - except: + except ValueError as e: _invoke(latest_sub_callback['error'], {'error': 'json decoding error'}) return + print code if code != 200: + print 'ERROR' _invoke(latest_sub_callback['error'], data) else: + print 'CALLBACK' _invoke(latest_sub_callback['callback'], data) else: try: data = json.loads(data) - except: + except ValueError: _invoke(self.error, {'error': 'json decoding error'}) return @@ -86,6 +90,12 @@ def _urllib_request_2(url, timeout=320): resp = urllib2.urlopen(url, timeout=timeout) except urllib2.HTTPError as http_error: resp = http_error + except urllib2.URLError as error: + #print error.reason + msg = { "message" : str(error.reason)} + #print str(msg) + return (json.dumps(msg),0) + return (resp.read(), resp.code) @@ -93,7 +103,7 @@ def _urllib_request_3(url, timeout=320): #print(url) try: resp = urllib.request.urlopen(url, timeout=timeout) - except urllib.request.HTTPError as http_error: + except (urllib.request.HTTPError, urllib.request.URLError) as http_error: resp = http_error r = resp.read().decode("utf-8") #print(r) @@ -170,7 +180,7 @@ class Pubnub(PubnubCoreAsync): response = _urllib_request(url, timeout=320) try: resp_json = json.loads(response[0]) - except: + except ValueError: return [0, "JSON Error"] if response[1] != 200 and 'status' in resp_json: |
