Skip to content

python -m websockets blocks until open_timeout when connection fails #1592

Closed
@aaugustin

Description

@aaugustin
$ python -m websockets wss://.../
^C
Traceback (most recent call last):
  File "/Users/myk/dev/websockets/src/websockets/sync/client.py", line 378, in connect
    connection.handshake(
    ~~~~~~~~~~~~~~~~~~~~^
        additional_headers,
        ^^^^^^^^^^^^^^^^^^^
        user_agent_header,
        ^^^^^^^^^^^^^^^^^^
        deadline.timeout(),
        ^^^^^^^^^^^^^^^^^^^
    )
    ^
  File "/Users/myk/dev/websockets/src/websockets/sync/client.py", line 101, in handshake
    raise self.protocol.handshake_exc
  File "/Users/myk/dev/websockets/src/websockets/client.py", line 325, in parse
    self.process_response(response)
    ~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^
  File "/Users/myk/dev/websockets/src/websockets/client.py", line 142, in process_response
    raise InvalidStatus(response)
websockets.exceptions.InvalidStatus: server rejected WebSocket connection: HTTP 302

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "/Users/myk/dev/websockets/src/websockets/__main__.py", line 159, in <module>
    main()
    ~~~~^^
  File "/Users/myk/dev/websockets/src/websockets/__main__.py", line 131, in main
    websocket = connect(args.uri)
  File "/Users/myk/dev/websockets/src/websockets/sync/client.py", line 385, in connect
    connection.recv_events_thread.join()
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^
  File "/Users/myk/.pyenv/versions/3.13.1/lib/python3.13/threading.py", line 1092, in join
    self._handle.join(timeout)
    ~~~~~~~~~~~~~~~~~^^^^^^^^^
KeyboardInterrupt

Connecting to the same server directly with websockets.sync.client.connect doesn't block.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions