Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import asyncio
- import websockets
- import json
- ws_url = "ws://127.0.0.1:8000/ws/order_statuses/"
- token = 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VybmFtZSI6IjEyMzQiLCJpYXQiOjE1' \
- 'OTg4NTg4NTUsImV4cCI6NTkxODg1ODg1NSwianRpIjoiZjViNDM4MzQtYTUwOC00NDc5LWFjM2' \
- 'QtM2VkY2M2MzRmYmIwIiwidXNlcl9pZCI6MSwib3JpZ19pYXQiOjE1OTg4NTg4NTV9.WP_mv8c' \
- 'LHC61RarqGpEZMKUDgJd6eFI_wRe5zOqC0UE'
- auth_headers = {'Authorization': 'Bearer {}'.format(token)}
- async def command_receiver():
- async with websockets.connect(ws_url, extra_headers=auth_headers) as websocket:
- await websocket.send('ping')
- message = await websocket.recv()
- msg_as_json = json.loads(message)
- print(msg_as_json['message'])
- while True:
- message = await websocket.recv()
- print(message)
- asyncio.get_event_loop().run_until_complete(command_receiver())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement