简体   繁体   中英

how connect to lightstreamer with python?

i want to connect to lightstramer with python

lightstreamer example

i try

import asyncio
import websockets as websockets

header = {
    'Accept-Encoding': 'gzip, deflate, br',
    'Accept-Language': 'en-US,en;q=0.9,fa;q=0.8',
    'Cache-Control': 'no-cache',
    'Connection': 'Upgrade',
    'Host': 'push.lightstreamer.com',
    'Origin': 'https://demos.lightstreamer.com',
    'Pragma': 'no-cache',
    'Sec-WebSocket-Extensions': 'permessage-deflate; client_max_window_bits',
    'Sec-WebSocket-Key': '0JsNTUnSx4IOsbmuLusyaw==',
    'Sec-WebSocket-Protocol': 'TLCP-2.1.0.lightstreamer.com',
    'Sec-WebSocket-Version': '13',
    'Upgrade': 'websocket',
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.163 '
                  'Safari/537.36',
}

async def hello():
async with websockets.connect('wss://push.lightstreamer.com/lightstreamer', extra_headers=header) as websocket:
        greeting = await websocket.recv()
        print(greeting)
asyncio.get_event_loop().run_until_complete(hello())

but always get error

websockets.exceptions.InvalidStatusCode: server rejected WebSocket connection: HTTP 400

how can i connect to this and get data??what library i need?

Currently, Lightstreamer does not offer an official python client library, but you could leverage this simple example , which uses HTTP Streaming for communicating with a Lightstreamer server instance.

Moreover, have a look at the TLCP Specifications for more details about how to implement the communication protocol.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM