I am trying to use websockets to stream data from an API and I am receiving a attribute error. 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' "
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". This should solve your problems.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.