Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python Websocket Example not working #1535

Closed
smcHannah opened this issue Sep 13, 2024 · 2 comments
Closed

Python Websocket Example not working #1535

smcHannah opened this issue Sep 13, 2024 · 2 comments
Assignees
Labels
bug Something isn't working

Comments

@smcHannah
Copy link

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

  1. Change the OpenC3 API password to my own in cosmos_web_socket_example.py
  2. Run cosmos_web_socket_example.py
  3. 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 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)
  4. 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()}"
  5. Run cosmos_web_socket_example.py again
  6. Successfully receive and print all the requested items.

Environment

  • OS: Windows 11
  • OpenC3 COSMOS Open Source 5.18.0
  • Browser: Chrome
@jmthomas
Copy link
Member

Hmm, this change was introduced in #1424.

@jmthomas jmthomas added the bug Something isn't working label Nov 5, 2024
@ryanmelt
Copy link
Member

ryanmelt commented Nov 6, 2024

This was fixed in the 5.20.0 release with #1675

@ryanmelt ryanmelt closed this as completed Nov 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants