相关文章推荐

Hi all. I’m trying to get data (messages) from a device (requires a web socket connection).

and I’m trying to do this on the external IP of the server

import asyncio
import websockets

async def get_websocket_data():
url = “ws://external_ip:port/api/devices/000000000000000/events”
headers = {
“Authorization”: “Bearer ” #jwt token from login request’s response
async with websockets.connect(url, extra_headers=headers) as websocket:
while True:
data = await websocket.recv()
print(data)
asyncio.get_event_loop().run_until_complete(get_websocket_data())

but the result is:
{“error”:{“grpcCode”:16,“httpCode”:401,“message”:“authentication failed: get token from context error: no authorization-data in metadata”,“httpStatus”:“Unauthorized”,“details”:[]}}

def getDataLogsConnection(devEUI): wsURL = f"ws://your_IP:port/api/devices/{devEUI}/events" ws = websocket.WebSocketApp( wsURL, on_open=on_open, on_message=on_message, on_close=on_close, on_error=on_error, header={"Sec-Websocket-Protocol": "Bearer, token"} #you can get it fron login request's response ws.run_forever() devEUI = "000000000000000" getDataLogsConnection(devEUI)
 
推荐文章