Closed ddombrowsky closed 3 years ago
I tried installing the PPA for python 3.6, and it still will not run.
Tried with versions:
$ python --version
Python 3.6.15
$ pip list | grep webso
websocket 0.2.1
websocket-client 1.2.1
Hi @ddombrowsky, I tried to reproduce your issue. I noticed something strange with pip installation of packages.
Initial working state where the script worked without AttributeError: module 'websocket' has no attribute 'enableTrace'
streaming-api-client $ python3 --version
Python 3.9.5
streaming-api-client $ pip3 list | grep webso
websocket 0.2.1
websocket-client 1.2.1
Next, I uninstalled the 'websocket' package:
Found existing installation: websocket 0.2.1
Uninstalling websocket-0.2.1:
Would remove:
/usr/local/lib/python3.9/site-packages/websocket-0.2.1.dist-info/*
/usr/local/lib/python3.9/site-packages/websocket/*
Would not remove (might be manually added):
/usr/local/lib/python3.9/site-packages/websocket/_abnf.py
/usr/local/lib/python3.9/site-packages/websocket/_app.py
/usr/local/lib/python3.9/site-packages/websocket/_cookiejar.py
/usr/local/lib/python3.9/site-packages/websocket/_core.py
/usr/local/lib/python3.9/site-packages/websocket/_exceptions.py
/usr/local/lib/python3.9/site-packages/websocket/_handshake.py
/usr/local/lib/python3.9/site-packages/websocket/_http.py
/usr/local/lib/python3.9/site-packages/websocket/_logging.py
/usr/local/lib/python3.9/site-packages/websocket/_socket.py
/usr/local/lib/python3.9/site-packages/websocket/_ssl_compat.py
/usr/local/lib/python3.9/site-packages/websocket/_url.py
/usr/local/lib/python3.9/site-packages/websocket/_utils.py
/usr/local/lib/python3.9/site-packages/websocket/tests/__init__.py
/usr/local/lib/python3.9/site-packages/websocket/tests/data/header01.txt
/usr/local/lib/python3.9/site-packages/websocket/tests/data/header02.txt
/usr/local/lib/python3.9/site-packages/websocket/tests/data/header03.txt
/usr/local/lib/python3.9/site-packages/websocket/tests/echo-server.py
/usr/local/lib/python3.9/site-packages/websocket/tests/test_abnf.py
/usr/local/lib/python3.9/site-packages/websocket/tests/test_app.py
/usr/local/lib/python3.9/site-packages/websocket/tests/test_cookiejar.py
/usr/local/lib/python3.9/site-packages/websocket/tests/test_http.py
/usr/local/lib/python3.9/site-packages/websocket/tests/test_url.py
/usr/local/lib/python3.9/site-packages/websocket/tests/test_websocket.py
Proceed (Y/n)? y
Successfully uninstalled websocket-0.2.1
Then I got the error you mentioned:
streaming-api-client $ python3 simple_app.py
Traceback (most recent call last):
File "/Users/karthikeyandhandapani/Downloads/streaming-api-client/simple_app.py", line 67, in <module>
websocket.enableTrace(True)
AttributeError: module 'websocket' has no attribute 'enableTrace'
To fix this, I reinstalled 'websocket', it still had the error. I then uninstalled 'websocket-client' package and reinstalled 'websocket-client' package. Then, the script started working. Could you try something similar?
streaming-api-client $ python3 simple_app.py
--- request header ---
GET /streaming/api HTTP/1.1
Upgrade: websocket
Host: internal-ui.central.arubanetworks.com
Origin: http://internal-ui.central.arubanetworks.com
Sec-WebSocket-Key: xxxxxxxx==
Sec-WebSocket-Version: 13
Connection: Upgrade
UserName: abc@gmail.com
Authorization: xxxxxxxxxxx
Topic: monitoring
...
...
Final list:
streaming-api-client $ python3 --version
Python 3.9.5
streaming-api-client $ pip3 list | grep webso
websocket 0.2.1
websocket-client 1.2.1
@karthikeyan-dhandapani inspired by your suggestion, I tried this:
pip remove -r requirements.txt
(or just start from fresh virtualenv)websocket
from the requirements.pip install -r requirements.txt
Then things seemed to work.
$ python simple_app.py
--- request header ---
GET /streaming/api HTTP/1.1
Upgrade: websocket
Host: app-uswest4.central.arubanetworks.com
Origin: http://app-uswest4.central.arubanetworks.com
Sec-WebSocket-Key: ...
Sec-WebSocket-Version: 13
Connection: Upgrade
UserName: ...
Authorization: ...
Topic: monitoring
-----------------------
--- response header ---
HTTP/1.1 101 Switching Protocols
Date: Fri, 17 Sep 2021 00:30:31 GMT
Connection: upgrade
Upgrade: websocket
Sec-WebSocket-Accept:
Strict-Transport-Security: max-age=31536000; includeSubDomains
X-Content-Type-Options: nosniff
X-Frame-Options: SAMEORIGIN
X-Request-Start: t=1631838631.320
X-XSS-Protection: 1; mode=block
-----------------------
Start Streaming Data!
It appears that websocket
and websocket-client
are incompatible. It seems to depend on which one was installed last as to who wins (or loses) the race.
Patch is:
diff --git a/streaming-api-client/requirements.txt b/streaming-api-client/requirements.txt
index c5e80ce..367a7f3 100644
--- a/streaming-api-client/requirements.txt
+++ b/streaming-api-client/requirements.txt
@@ -3,5 +3,4 @@ greenlet
protobuf
six
requests
-websocket
websocket-client
Note: I did get another error about on_close
not taking the right number of arguments. I worked around it by adding some dummy variables:
diff --git a/streaming-api-client/simple_app.py b/streaming-api-client/simple_app.py
index b72359f..134f4db 100644
--- a/streaming-api-client/simple_app.py
+++ b/streaming-api-client/simple_app.py
@@ -41,7 +41,7 @@ def on_message(ws, message):
def on_error(ws, error):
print(error)
-def on_close(ws):
+def on_close(ws,a,b):
print("### closed ###")
def on_open(ws):
btw versions for the working version are python 3.8.10 and websocket-client 1.2.1.
Thanks for the diff. Also try out advanced version of streaming client if required. I am closing this issue now, will fix this shortly along with upcoming changes for next version of Aruba central.
Using this documentation, I attempted to get a test aruba web-socket listener up and running. After cloning, I installed the requirements with
I set up the key, and then attempted a run:
It appears the code no longer works in python 3.8.
Versions: