AttributeError: 'module' 对象没有属性 'WebSocketApp' [英] AttributeError: 'module' object has no attribute 'WebSocketApp'
问题描述
我正在尝试使用 Python 连接到 API,使用 WebSocketApp,但我似乎无法做到.无论我尝试什么,我都会收到此错误:
I'm trying to connect to an API with python, using WebSocketApp, and I cannot seem to do it. No matter what I try, I keep getting this error:
AttributeError: 'module' 对象没有属性 'WebSocketApp'
这是我正在使用的简单代码
Here is the simple code I am using
import websocket
import json
def on_open(ws):
json_data = json.dumps({'data':'value'})
ws.send(json_data)
def on_message(ws, message):
print('data update: %s' % message)
if __name__ == "__main__":
apiUrl = "appurl"
ws = websocket.WebSocketApp(apiUrl, on_message = on_message, on_open = on_open)
ws.run_forever()
非常感谢任何帮助,我在网上找到的所有解决方案都不适用于我.
Any help will be greatly appreciated, all the solutions I have found online have not worked for me.
推荐答案
看起来您正在尝试使用 websocket-client
包的功能,而不仅仅是 websocket代码> 包.从命令行 Pip-install
websocket-client
(或使用您拥有的任何其他包管理器安装它),然后再次尝试运行您的代码.
It looks like you're trying to use features of the websocket-client
package and not just the websocket
package. Pip-install websocket-client
from the command line (or install it using whatever other package manager you have), then try running your code again.
pip install websocket-client
这篇关于AttributeError: 'module' 对象没有属性 'WebSocketApp'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!