Connect to the WebSocket server at ``uri``. This coroutine returns a :class:`ClientConnection` instance, which you can use to send and receive messages. :func:`connect` may be used as an asynchronous context manager:: from websockets.asyncio.client import connect
| 176 | |
| 177 | # This is spelled in lower case because it's exposed as a callable in the API. |
| 178 | class connect: |
| 179 | """ |
| 180 | Connect to the WebSocket server at ``uri``. |
| 181 | |
| 182 | This coroutine returns a :class:`ClientConnection` instance, which you can |
| 183 | use to send and receive messages. |
| 184 | |
| 185 | :func:`connect` may be used as an asynchronous context manager:: |
| 186 | |
| 187 | from websockets.asyncio.client import connect |
| 188 | |
| 189 | async with connect(...) as websocket: |
| 190 | ... |
| 191 | |
| 192 | The connection is closed automatically when exiting the context. |
| 193 | |
| 194 | :func:`connect` can be used as an infinite asynchronous iterator to |
| 195 | reconnect automatically on errors:: |
| 196 | |
| 197 | async for websocket in connect(...): |
| 198 | try: |
| 199 | ... |
| 200 | except websockets.exceptions.ConnectionClosed: |
| 201 | continue |
| 202 | |
| 203 | If the connection fails with a transient error, it is retried with |
| 204 | exponential backoff. If it fails with a fatal error, the exception is |
| 205 | raised, breaking out of the loop. |
| 206 | |
| 207 | The connection is closed automatically after each iteration of the loop. |
| 208 | |
| 209 | Args: |
| 210 | uri: URI of the WebSocket server. |
| 211 | origin: Value of the ``Origin`` header, for servers that require it. |
| 212 | extensions: List of supported extensions, in order in which they |
| 213 | should be negotiated and run. |
| 214 | subprotocols: List of supported subprotocols, in order of decreasing |
| 215 | preference. |
| 216 | compression: The "permessage-deflate" extension is enabled by default. |
| 217 | Set ``compression`` to :obj:`None` to disable it. See the |
| 218 | :doc:`compression guide <../../topics/compression>` for details. |
| 219 | additional_headers (HeadersLike | None): Arbitrary HTTP headers to add |
| 220 | to the handshake request. |
| 221 | user_agent_header: Value of the ``User-Agent`` request header. |
| 222 | It defaults to ``"Python/x.y.z websockets/X.Y"``. |
| 223 | Setting it to :obj:`None` removes the header. |
| 224 | proxy: If a proxy is configured, it is used by default. Set ``proxy`` |
| 225 | to :obj:`None` to disable the proxy or to the address of a proxy |
| 226 | to override the system configuration. See the :doc:`proxy docs |
| 227 | <../../topics/proxies>` for details. |
| 228 | process_exception: When reconnecting automatically, tell whether an |
| 229 | error is transient or fatal. The default behavior is defined by |
| 230 | :func:`process_exception`. Refer to its documentation for details. |
| 231 | open_timeout: Timeout for opening the connection in seconds. |
| 232 | :obj:`None` disables the timeout. |
| 233 | ping_interval: Interval between keepalive pings in seconds. |
| 234 | :obj:`None` disables keepalive. |
| 235 | ping_timeout: Timeout for keepalive pings in seconds. |
no outgoing calls
no test coverage detected
searching dependent graphs…