How do I get the result of pubnub.time() when called? This is definitely related to me not fully knowing python that well...
I'm trying to call pubnub.time() to test when network connectivity restores so pubnub can reconnect and I can resubscribe to the necessary channel. I can't seem to get the desired output. Per the pubnub docs, time() has 3 methods that will return an int, string, or date.
envelope = pubnub.time() envelope.int() outputs error envelope.str() outputs error envelope.date_time() outputs error
The only thing that I can get to work is
print(envelope) which yields
<pubnub.endpoints.time.Time object at 0x75fb8f50>.
I won't delve into how many iterations of things I've tried on this, and come begging for help.
We have a couple remote systems that we're wanting to use PubNub to gather data points from hardware that's connected to the machine. Data requests will come in, and PubNub needs to respond to the requests. Our main issue is that these remote locations have very flaky DSL that goes down for hours to days at a time, and while our python app is still running, PubNub does not reconnect. Trying reconnect_policy with LINEAR and EXPONENTIAL both fail to reconnect after an internet outage. Small, short outages will recover though. Aside from this, PubNub works great for this setup.
Here's my setup config
pnconfig = PNConfiguration() pnconfig.subscribe_key = 'sub' pnconfig.publish_key = 'pub' pnconfig.reconnect_policy = 'PNReconnectionPolicy.EXPONENTIAL' pnconfig.daemon = True pnconfig.ssl = True
Here's our subscribe call back:
class MySubscribeCallback(SubscribeCallback): def presence(self, pubnub, presence): pass def status(self, pubnub, status): if status.is_error(): logger.error("PN Error" + str(status.error_data.exception)) if status.category == PNStatusCategory.PNUnexpectedDisconnectCategory: logger.error("PN Unexpected Disconnect") pubnub.reconnect() pass elif status.category == PNStatusCategory.PNConnectedCategory: logger.info("PN Connected") elif status.category == PNStatusCategory.PNReconnectedCategory: logger.warning("PN Re-Connected") pubnub.subscribe().channels('devChannel').execute() pass elif status.category == PNStatusCategory.PNDecryptionErrorCategory: logger.error("PN Decryption Error") pass