无法连接到Websocket地址?

2024-09-26 18:04:53 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图通过websocket地址连接,但我的脚本在数据恢复时出错。你知道吗

import requests
from websocket import create_connection

def conWs():
    ws = create_connection('wss://olymptrade.com/ds/v3')
    #ws.send('[{"t":1,"e":105,"d":[{"source":"platform"}]}]')
    #ws.send('[{"t":2,"e":90,"uuid":"JR20G7HQ62P0DURZO6F"}]')

    print(ws.connected)

    while True:
        result = ws.recv()
        print ("Received '%s'" % result)

我原以为它会连接并开始接收websocket数据,但脚本中断并出现以下错误:

websocket._exceptions.WebSocketConnectionClosedException: Connection is already closed.

Tags: fromimport脚本sendws地址defcreate
1条回答
网友
1楼 · 发布于 2024-09-26 18:04:53

看起来你需要使用不同的方法。你知道吗

Short-lived one-off send-receive

This (your code above) is if you want to communicate a short message and disconnect immediately when done.

看看长寿命连接的例子in the docs,请告诉我这些修改是否适用于您。祝你好运!你知道吗

相关问题 更多 >

    热门问题