python测试websocket接口

import json
from websocket._core import create_connection
# 安装 websocket-client 

host = "wss://****"
ws = create_connection(host,timeout=3)

try:
    # 发送data
    data = ""
    ws.send(str(json.dumps(data)))
    # 获取返回值
    result = ws.recv()
    print(result)
except Exception as e:
    print(e)
finally:
    ws.close()

 

posted @ 2022-07-11 17:49  OTAKU_nicole  阅读(107)  评论(0编辑  收藏  举报