Skip to content

Instantly share code, notes, and snippets.

@jacobian
Created February 4, 2013 17:00
Show Gist options
  • Save jacobian/4707980 to your computer and use it in GitHub Desktop.
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.
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)
@stephenlb
Copy link

Thank you for providing this option! We are in the process of implement a callback on error with detailed response information. Most atomic calls like publish and history will be simple on error. While subscribe will require something more sophisticated. Thank you for the gist!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment