有人可以帮我弄清楚为什么我会收到此异常吗?即使我配置了 suscribe 键,但似乎没有。这是异常:“订阅循环中的异常:订阅密钥未配置重新连接策略已禁用,请手动处理重新连接。”import 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贡献1796条经验 获得超10个赞
无法收到错误“订阅循环中的异常:订阅密钥未配置重新连接策略已禁用,请手动处理重新连接。”。
使用了代码块:
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
添加回答
举报
0/150
提交
取消