Python Websockets module has no attribute

I have this python file that sends a websocket message to my python server. But it keeps getting errors, I saw these errors before, but I can’t fix them, my python version is python2.7

#!/usr/bin/python import websocket import sys val = sys.argv[1] ws = websocket.create_connection("ws://ipaddress:9001") ws.send(val) ws.close() 

Error

 Traceback (most recent call last): File "./test.py", line 5, in <module> ws = websocket.create_connection("ws://ipaddress:9001") AttributeError: 'module' object has no attribute 'create_connection' 
+7
source share
2 answers

you installed the wrong library ( websocket ) try installing websocket-client

 $ pip install websocket-client 

and then your code should work just fine

+13
source

See the answer from falsetru here: AttributeError: the 'module' object does not have the 'WebSocketApp' attribute

Msgstr "Make sure you do not name your file as websocket.py; otherwise, it will prevent the import of the required third-party websocket module; because your module is searched first according to the search path for the sys.path module.

Rename your module under a different name and be sure to clear websocket.pyc if it was generated. "

+6
source

Source: https://habr.com/ru/post/1011641/


All Articles