有人可以幫我弄清楚為什么我會(huì)收到此異常嗎?即使我配置了 suscribe 鍵,但似乎沒有。這是異常:“訂閱循環(huán)中的異常:訂閱密鑰未配置重新連接策略已禁用,請(qǐng)手動(dòng)處理重新連接?!眎mport timefrom pubnub.pubnub import PubNubfrom pubnub.pnconfiguration import PNConfigurationfrom pubnub.callbacks import SubscribeCallbackfrom backend.blockchain.block import Blockpnconfig = PNConfiguration()pnconfig.suscribe_key = 'sub-c-6d0fe192-dee4-11ea-9b19-...'pnconfig.publish_key = 'pub-c-c3553c68-bf24-463c-ae43-...'CHANNELS = {'TEST': 'TEST','BLOCK': 'BLOCK'}class Listener(SubscribeCallback): def __init__(self, blockchain): self.blockchain = blockchain def message(self, pubnub, message_object): print('\n-- Channel: {message_object.channel} | Message: {message_object.message}') if message_object.channel == CHANNELS['BLOCK']: block = Block.from_json(message_object.message) potential_chain = self.blockchain.chain[:] potential_chain.append(block) try: self.blockchain.replace_chain(potential_chain) print('\n -- Successfully replaced the local chain') except Exception as e: print('\n -- Did not replace chain: {e}')class PubSub(): """ Handles the publish/subscribe layer of the application. Provides communication between the nodes of the blockchain network. """ def __init__(self, blockchain): self.pubnub = PubNub(pnconfig) self.pubnub.subscribe().channels(CHANNELS.values()).execute() self.pubnub.add_listener(Listener(blockchain)) def publish(self, channel, message): """ Publish the message object to the channel. """ self.pubnub.publish().channel(channel).message(message).sync() def broadcast_block(self, block): """ Broadcast a block object to all nodes. """
1 回答

白衣染霜花
TA貢獻(xiàn)1796條經(jīng)驗(yàn) 獲得超10個(gè)贊
無法收到錯(cuò)誤“訂閱循環(huán)中的異常:訂閱密鑰未配置重新連接策略已禁用,請(qǐng)手動(dòng)處理重新連接。”。
使用了代碼塊:
pnconfig = PNConfiguration()
pnconfig.subscribe_key = "my_subkey"
pnconfig.publish_key = "my_pubkey"
pnconfig.ssl = True
pnconfig.uuid = "my_custom_uuid"
pnconfig.reconnect_policy = "LINEAR"
pubnub = PubNub(pnconfig)
來自頁面: https: //www.pubnub.com/docs/python/api-reference-configuration 并添加:
PNReconnectionPolicy.NONE
添加回答
舉報(bào)
0/150
提交
取消