简体   繁体   English

Websocket 不会 function

[英]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.

相关问题 为什么我不能在 function 中使用 websocket - Why can't I use websocket in a function 使用异步函数内部的异步连接到 websocket - Connecting to websocket with async inside async function Flask Socketio 是否支持 JS 中的 Websocket() Function? - Does Flask Socketio Support the Websocket() Function in JS? 如何将列表变量从 websocket 匹配到连接的其他 function? (websocket 速度快) - how can match the list variable from websocket to connected other function? (websocket speed fast) 如何在Tornado.WebSocket类中异步运行循环函数? - How to run a looping function asynchronously in a Tornado.WebSocket class? 我有使用羊驼 websocket 的代码,但有一个 function 未定义 - I have this code using the alpaca websocket but there is a function which is not defined 如何从异步函数 websocket.send() 数据 - How to websocket.send() data from an async function 使用 websocket 数据每新分钟触发一次函数 - Trigger function every new minute w/ websocket data on_open function 在打开 websocket 连接时无法运行? - on_open function is failing to run when opening websocket connection? asyncio:运行一个函数与来自websocket客户端的多个请求进行线程化 - asyncio: run one function threaded with multiple requests from websocket clients
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM