Skip to content

Commit

Permalink
Fix 'unexpected keyword argument extra_headers' error in websockets.c…
Browse files Browse the repository at this point in the history
…onnect()
  • Loading branch information
dumitrugutu committed Nov 11, 2024
1 parent e47cd2f commit 2ac5a0d
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 7 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [2.0.3] - 2024-11-11

## Fixed

- Unexpected `keyword argument 'extra_headers'` error in `websockets.connect()`
by upgrading the `websockets` library version to `14.0` and renaming `extra_headers` to `additional_headers`
as instructed here https://websockets.readthedocs.io/en/stable/howto/upgrade.html#arguments-of-connect

## [2.0.2] - 2024-10-04

## Added
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.0.2
2.0.3
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
websockets>=10
websockets>=14.0
httpx[http2]~=0.23
polling2~=0.5
toml~=0.10.2
Expand Down
2 changes: 1 addition & 1 deletion speechmatics/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,7 @@ async def run(
ping_timeout=self.connection_settings.ping_timeout_seconds,
# Don't limit the max. size of incoming messages
max_size=None,
extra_headers=extra_headers,
additional_headers=extra_headers,
) as self.websocket:
await self._communicate(stream, audio_settings)
finally:
Expand Down
4 changes: 2 additions & 2 deletions tests/mock_rt_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,8 @@ def dummy_add_transcript():
async def mock_server_handler(websocket, logbook):
mock_server_handler.next_audio_seq_no = 1
address, _ = websocket.remote_address
logbook.connection_request = websocket.request_headers
logbook.path = websocket.path
logbook.connection_request = websocket.request.headers
logbook.path = websocket.request.path

# Begin a connection
logging.info("%s %s", address, "connected")
Expand Down
4 changes: 2 additions & 2 deletions tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ async def test_send_message(mock_server, message_type: str, message_data: Any):
ssl=ws_client.connection_settings.ssl_context,
ping_timeout=ws_client.connection_settings.ping_timeout_seconds,
max_size=None,
extra_headers=None,
additional_headers=None,
) as ws_client.websocket:
await ws_client.send_message(message_type, message_data)
assert message_type in [
Expand Down Expand Up @@ -377,7 +377,7 @@ def call_exit(*args, **kwargs):
except Exception:
assert len(connect_mock.mock_calls) == 1
assert (
connect_mock.mock_calls[0][2]["extra_headers"] == extra_headers
connect_mock.mock_calls[0][2]["additional_headers"] == extra_headers
), f"Extra headers don't appear in the call list = {connect_mock.mock_calls}"


Expand Down

0 comments on commit 2ac5a0d

Please sign in to comment.