AttributeError:“模块"对象没有属性"WebSocketApp" [英] AttributeError: 'module' object has no attribute 'WebSocketApp'
问题描述
我正在尝试使用WebSocketApp使用python连接到API,但似乎无法做到这一点.无论我尝试什么,我都会不断收到此错误:
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:模块"对象没有属性"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:“模块"对象没有属性"WebSocketApp"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!