Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/357.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python pubnub异步IO不发布数据_Python_Python 3.x_Python Asyncio_Pubnub - Fatal编程技术网

Python pubnub异步IO不发布数据

Python pubnub异步IO不发布数据,python,python-3.x,python-asyncio,pubnub,Python,Python 3.x,Python Asyncio,Pubnub,我正在使用PubNub Asyncio库发布数据,下面是我的代码 import asyncio import os from pubnub.exceptions import PubNubException from pubnub.pnconfiguration import PNConfiguration from pubnub.pubnub_asyncio import PubNubAsyncio def publish_callback(result, status): pri

我正在使用
PubNub Asyncio
库发布数据,下面是我的代码

import asyncio
import os

from pubnub.exceptions import PubNubException
from pubnub.pnconfiguration import PNConfiguration
from pubnub.pubnub_asyncio import PubNubAsyncio

def publish_callback(result, status):
    print(status)

class PubNubIntegrator:
    def __init__(self):
        print("In initialize")
        pn_configuration = PNConfiguration()
        pn_configuration.publish_key = os.environ['PUB_KEY']
        pn_configuration.subscribe_key = os.environ['SUB_KEY']
        pn_configuration.ssl = True
        self.pubnub = PubNubAsyncio(pn_configuration)


    async def publish_data(self, message, channel_name):
        print('message on channel {0}'.format(channel_name))
        try:
            asyncio.ensure_future(self.pubnub.publish().channel(channel_name).message(message).future()).add_done_callback(publish_callback)
        except PubNubException as e:
            print("Error while publishing data", message)
我从另一个函数调用它

async def stream(self):
        result = { "mesage": "data"} 
        pn_integrator = PubNubIntegrator()
        await pn_integrator.publish_data(result, 'demo_channel')

但它不起作用,并且不将数据发布到通道。

哪种版本的Python?哪个版本的PubNub Python Async.io SDK?您是否可以提供(许多人希望直接向其报告)发布/订阅键等]?但一定要确保您使用的是最新版本的PubNub SDK,最好是Python本身的v3.7。最新的更新可能就是解决方案:根据我的建议,你有没有取得任何进展?如有必要,请将您的查询提交至,并包含此SO链接,以便我们回复。是的,我已向
PubNub