Reputation: 942
i want to connect to lightstramer with python
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?
Upvotes: 3
Views: 1492
Reputation: 36
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.
Upvotes: 2