Describe the bug
The Python WebSocket API attempts to connect with a truncated authentication token, which results in a ConnectionClosedOK exception saying "received 1000 (OK); then sent 1000 (OK)" when running cosmos_web_socket_example.py with COSMOS Open Source.
To Reproduce
Change the OpenC3 API password to my own in cosmos_web_socket_example.py
Run cosmos_web_socket_example.py
Get the following traceback:
Traceback (most recent call last):File "c:\Users\...\cosmos_web_socket_example.py", line 24, in <module>with StreamingWebSocketApi() as api:File "C:\Users\...\AppData\Local\Programs\Python\Python312\Lib\site-packages\openc3\script\web_socket_api.py", line 62, in __exit__self.disconnect()File "C:\Users\...\AppData\Local\Programs\Python\Python312\Lib\site-packages\openc3\script\web_socket_api.py", line 153, in disconnectself.unsubscribe()File "C:\Users\...\AppData\Local\Programs\Python\Python312\Lib\site-packages\openc3\script\web_socket_api.py", line 110, in unsubscribeself.stream.write(json.dumps(json_hash))File "C:\Users\...\AppData\Local\Programs\Python\Python312\Lib\site-packages\openc3\streams\web_socket_client_stream.py", line 50, in writeself.connection.send(data)File "C:\Users\...\AppData\Local\Programs\Python\Python312\Lib\site-packages\websockets\sync\connection.py", line 281, in sendwith self.send_context():File "C:\Users\...\AppData\Local\Programs\Python\Python312\Lib\contextlib.py", line 137, in __enter__return next(self.gen)^^^^^^^^^^^^^^File "C:\Users\...\AppData\Local\Programs\Python\Python312\Lib\site-packages\websockets\sync\connection.py", line 715, in send_contextraise self.protocol.close_exc from original_excwebsockets.exceptions.ConnectionClosedOK: received 1000 (OK); then sent 1000 (OK)
Change line 131 of web_socket_api.py from
final_url = self.url + f"?scope={self.scope}&authorization={self.authentication.token()[7:]}"
to
final_url = self.url + f"?scope={self.scope}&authorization={self.authentication.token()}"
Run cosmos_web_socket_example.py again
Successfully receive and print all the requested items.
Describe the bug The Python WebSocket API attempts to connect with a truncated authentication token, which results in a ConnectionClosedOK exception saying "received 1000 (OK); then sent 1000 (OK)" when running cosmos_web_socket_example.py with COSMOS Open Source.
To Reproduce
Traceback (most recent call last):
File "c:\Users\...\cosmos_web_socket_example.py", line 24, in <module>
with StreamingWebSocketApi() as api:
File "C:\Users\...\AppData\Local\Programs\Python\Python312\Lib\site-packages\openc3\script\web_socket_api.py", line 62, in __exit__
self.disconnect()
File "C:\Users\...\AppData\Local\Programs\Python\Python312\Lib\site-packages\openc3\script\web_socket_api.py", line 153, in disconnect
self.unsubscribe()
File "C:\Users\...\AppData\Local\Programs\Python\Python312\Lib\site-packages\openc3\script\web_socket_api.py", line 110, in unsubscribe
self.stream.write(json.dumps(json_hash))
File "C:\Users\...\AppData\Local\Programs\Python\Python312\Lib\site-packages\openc3\streams\web_socket_client_stream.py", line 50, in write
self.connection.send(data)
File "C:\Users\...\AppData\Local\Programs\Python\Python312\Lib\site-packages\websockets\sync\connection.py", line 281, in send
with self.send_context():
File "C:\Users\...\AppData\Local\Programs\Python\Python312\Lib\contextlib.py", line 137, in __enter__
return next(self.gen)
^^^^^^^^^^^^^^
File "C:\Users\...\AppData\Local\Programs\Python\Python312\Lib\site-packages\websockets\sync\connection.py", line 715, in send_context
raise self.protocol.close_exc from original_exc
websockets.exceptions.ConnectionClosedOK: received 1000 (OK); then sent 1000 (OK)
final_url = self.url + f"?scope={self.scope}&authorization={self.authentication.token()[7:]}"
tofinal_url = self.url + f"?scope={self.scope}&authorization={self.authentication.token()}"
Environment