[英]Websocket will not function
I am trying to use websockets to stream data from an API and I am receiving a attribute error.我正在尝试将 websockets 用于来自 API 的 stream 数据,我收到一个属性错误。 any help would be much appreciated!任何帮助将非常感激!
import websocket
Stock_stream = 'wss://data.alpaca.markets/stream'
def on_open(ws)
#code
def on_message(ws, message)
#code
def on_close(ws)
#code
ws = websocket.WebSocketApp(Stock_stream, on_open=on_open, on_message=on_message, on_close=on_close)
ws.run_forever()
Traceback (most recent call last):
File "C:\Users\engli\PycharmProjects\hello\Alpaca_script.py", line 385, in <module>
ws = websocket.WebSocketApp(Stock_stream, on_open=on_open, on_message=on_message, on_close=on_close)
AttributeError: module 'websocket' has no attribute 'WebSocketApp'
WebSocketApp is also highlighted in yellow, it says, "cannot find reference 'WebSocketApp' in ' init .py' " WebSocketApp 也以黄色突出显示,上面写着“在 ' init .py' 中找不到引用 'WebSocketApp'”
Thank you谢谢
It seems as if you are using the incorrect library.似乎您使用的库不正确。 Erase the current "websocket" library and in the terminal type "pip install websocket-client".擦除当前的“websocket”库并在终端输入“pip install websocket-client”。 This should solve your problems.这应该可以解决您的问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.