Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/277.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中的websocket API?_Python_Python 3.x_Websocket - Fatal编程技术网

如何使用Python中的websocket API?

如何使用Python中的websocket API?,python,python-3.x,websocket,Python,Python 3.x,Websocket,我想消费以下物品 我试着去适应这个世界,但是我一事无成 import asyncio import websockets async def hello(): async with websockets.connect('ws://ws.weatherflow.com/swd/data') as websocket: await websocket.send({ "type":"listen_start", "device_id

我想消费以下物品

我试着去适应这个世界,但是我一事无成

import asyncio
import websockets

async def hello():
    async with websockets.connect('ws://ws.weatherflow.com/swd/data') as websocket:

        await websocket.send({
          "type":"listen_start",
          "device_id":1110,
          "id":"2098388936"
        })

        greeting = await websocket.recv()
        print(greeting)

asyncio.get_event_loop().run_until_complete(hello())

如何使用Python中的websocket API?这就是如何获得持续不断的天气信息流

似乎缺少api_键参数:

从:

  • 网袋

    • 打开websocket连接
    • wss://ws.weatherflow.com/swd/data?api_key=20c70eae-e62f-4d3b-b3a4-8586e90f3ac8

    • 通过websocket连接发送JSON消息,开始侦听演示设备的观察结果。发送此消息后,连接的websocket客户端应每分钟接收一条新的观察JSON消息

    • {“type”:“listen\u start”,“device\u id”:1110,“id”:“random-id-12345”}
我用以下代码实现了它:

import asyncio
import websockets

async def hello():
    async with websockets.connect('wss://swd.weatherflow.com/swd/data?api_key=20c70eae-e62f-4d3b-b3a4-8586e90f3ac8') as websocket:
        await websocket.send('{"type":"listen_start", "device_id":1110,"id": "2098388936"}')
        greeting = await websocket.recv()
        print(greeting)

asyncio.get_event_loop().run_until_complete(hello())
请注意,根据文档,此API密钥用于快速入门。请勿在应用程序中使用此密钥