订阅循环中的异常:未配置订阅密钥

有人可以帮我弄清楚为什么我会收到此异常吗?即使我配置了 suscribe 键,但似乎没有。


这是异常:“订阅循环中的异常:订阅密钥未配置重新连接策略已禁用,请手动处理重新连接。”


import time


from pubnub.pubnub import PubNub

from pubnub.pnconfiguration import PNConfiguration

from pubnub.callbacks import SubscribeCallback

from backend.blockchain.block import Block


pnconfig = 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.

            """





慕神8447489
浏览 123回答 1
1回答

白衣染霜花

无法收到错误“订阅循环中的异常:订阅密钥未配置重新连接策略已禁用,请手动处理重新连接。”。使用了代码块:pnconfig = PNConfiguration()pnconfig.subscribe_key = "my_subkey"pnconfig.publish_key = "my_pubkey"pnconfig.ssl = Truepnconfig.uuid = "my_custom_uuid"pnconfig.reconnect_policy = "LINEAR"pubnub = PubNub(pnconfig)来自页面: https: //www.pubnub.com/docs/python/api-reference-configuration 并添加:PNReconnectionPolicy.NONE
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python