I have this python script that sends a WebSocket message to my python server. But it keeps throwing errors. I have seen these errors before, but I can't seem to fix it. I use the 2.7.x
version.
#!/usr/bin/python
import websocket
import sys
val = sys.argv[1]
ws = websocket.create_connection("ws://ipaddress:9001")
ws.send(val)
ws.close()
The 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'
you've installed the wrong library (websocket
)
try installing websocket-client
$ pip install websocket-client
and then your code must work just fine
See the answer by falsetru here: AttributeError: 'module' object has no attribute 'WebSocketApp'
" Make sure that you didn't name your file as websocket.py; Otherwise, it will prevent import of the desired third-party module websocket; because your module is searched first according to sys.path module search path.
Rename your module to other name, and make sure to clean websocket.pyc if it was generated."
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With