2016-12-02 47 views
0

这是我的出版商:Python的PubNub用户没有打印出来的消息

from pubnub.pnconfiguration import PNConfiguration 
from pubnub.pubnub import PubNub 

def publish_callback(result, status): 
    print(result) 
    print(status) 
    # Handle PNPublishResult and PNStatus 

pnconfig = PNConfiguration() 

pnconfig.subscribe_key = 'sub-c-ec413276-b805-11e6-b737-xxxxx' 
pnconfig.publish_key = 'pub-c-528502df-76a6-4f07-8636-xxxxx' 

pubnub = PubNub(pnconfig) 

pubnub.publish().channel("awesomeChannel").message("hello!!").async(publish_callback) 

这是我的用户

from pubnub.pnconfiguration import PNConfiguration 
from pubnub.pubnub import PubNub 

from pubnubtets import MySubscribeCallback 
pnconfig = PNConfiguration() 

pnconfig.subscribe_key = 'sub-c-ec413276-b805-11e6-b737-xxxxx' 
pnconfig.publish_key = 'pub-c-528502df-76a6-4f07-8636-xxxxx' 
pubnub = PubNub(pnconfig) 

pubnub.add_listener(MySubscribeCallback()) 
pubnub.subscribe().channels('awesomeChannel').execute() 

这是我的回调:

from pubnub.callbacks import SubscribeCallback 
from pubnub.enums import PNStatusCategory 

class MySubscribeCallback(SubscribeCallback): 
    def presence(self, pubnub, presence): 
    print(presence) 

    def status(self, pubnub, status): 
    if status.category == PNStatusCategory.PNUnexpectedDisconnectCategory: 
     pass # This event happens when radio/connectivity is lost 

    elif status.category == PNStatusCategory.PNConnectedCategory: 
     # Connect event. You can do stuff like publish, and know you'll get it. 
     # Or just use the connected event to confirm you are subscribed for 
     # UI/internal notifications, etc 
     pass 
    elif status.category == PNStatusCategory.PNReconnectedCategory: 
     pass 
     # Happens as part of our regular operation. This event happens when 
     # radio/connectivity is lost, then regained. 
    elif status.category == PNStatusCategory.PNDecryptionErrorCategory: 
     pass 
     # Handle message decryption error. Probably client configured to 
     # encrypt messages and on live data feed it received plain text. 

    def message(self, pubnub, message): 
    print(message) 

问题我有,当我运行订阅它听,当我运行发布者发送消息hello!!我的回调ge但它当我打印消息打印出<pubnub.models.consumer.pubsub.PNMessageResult object at 0x108453278>。我希望它实际上向我展示我的消息hello!!

有什么我失踪?

回答