Reputation: 71
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
Upvotes: 1
Views: 1235
Reputation: 189
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.
Upvotes: 4