from pubnub.callbacks import SubscribeCallback from pubnub.enums import PNStatusCategory from pubnub.pnconfiguration import PNConfiguration from pubnub.pubnub import PubNub pnconfig = PNConfiguration() pnconfig.subscribe_key = 'sub-c-8187642a-d207-11e7-91cc-2ef9da9e0d0e' pnconfig.secure_key = 'sec-c-ODRkZmI4NzUtMmRjZi00Y2M2LWExM2UtMGZhYjM3ZTZlMjUy' pnconfig.publish_key = 'pub-c-3f7415bc-3090-4b10-ba90-1e27ee928302' pubnub = PubNub(pnconfig) def my_publish_callback(envelope, status): # Check whether request successfully completed or not if not status.is_error(): pass # Message successfully published to specified channel. else: pass # Handle message publish error. Check 'category' property to find out possible issue # because of which request did fail. # Request can be resent using: [status retry]; class MySubscribeCallback(SubscribeCallback): def presence(self, pubnub, presence): pass # handle incoming presence data def status(self, pubnub, status): if status.category == PNStatusCategory.PNUnexpectedDisconnectCategory: pass # This event happens when radio / connectivity is lost