AttributeError: module 'websocket' has no attribute 'WebSocketApp' python
时间: 2023-10-02 14:13:38 浏览: 183
报错信息中显示"AttributeError: module 'websocket' has no attribute 'WebSocketApp'",这是因为websocket模块中没有名为WebSocketApp的属性。
解决这个问题的方法是使用websocket-client库中的WebSocketApp类来代替。你需要导入websocket库的时候使用websocket-client替代websocket,并使用websocket.WebSocketApp来实例化WebSocketApp对象。例如:
```
import websocket
from websocket import WebSocketApp
ws = WebSocketApp("ws://www.xxxx.cn:7002/ws/channels/", on_message=on_message, on_error=on_error, on_close=on_close)
ws.on_open = on_open
ws.run_forever(ping_interval=60, ping_timeout=5)
```
通过以上修改,你应该能够成功使用WebSocketApp类来创建WebSocket连接了。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* *2* [AttributeError: module ‘websocket‘ has no attribute ‘enableTrace‘ 错误完全解决](https://blog.csdn.net/haichao0991/article/details/122752021)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"]
- *3* [AttributeError: module ‘websocket‘ has no attribute ‘enableTrace](https://blog.csdn.net/u014534808/article/details/113655577)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"]
[ .reference_list ]
阅读全文