Created
February 4, 2013 17:00
-
-
Save jacobian/4707980 to your computer and use it in GitHub Desktop.
Work around Pubnub swallowing errors until https://github.com/pubnub/pubnub-api/pull/179 is merged.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import urllib2 | |
from Pubnub import Pubnub as OriginalPubnub | |
class Pubnub(OriginalPubnub): | |
""" | |
The Pubnub client library silently swallows errors on sending a message | |
(see https://github.com/pubnub/pubnub-api/blob/master/python/3.3/Pubnub.py#L399-L400). | |
This works around that problem by copy/pasting the _request() function | |
and removing the bare except. | |
Pull request submitted: https://github.com/pubnub/pubnub-api/pull/179. | |
""" | |
## Build URL | |
def _request(self, request, origin=None, encode=True, params=None): | |
url = (origin or self.origin) + '/' + "/".join( | |
encode and self._encode(request) or request | |
) | |
## Add query params | |
if params is not None and len(params) > 0: | |
url = url + "?" + "&".join(params) | |
## Send Request Expecting JSONP Response | |
usock = urllib2.urlopen(url, None, 200) | |
response = usock.read() | |
usock.close() | |
return json.loads(response) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you for providing this option! We are in the process of implement a
callback
on error with detailed response information. Most atomic calls likepublish
andhistory
will be simple on error. Whilesubscribe
will require something more sophisticated. Thank you for the gist!