diff --git a/python-api-examples/non_streaming_server.py b/python-api-examples/non_streaming_server.py index 3dd12564e..3ffa8b7d5 100755 --- a/python-api-examples/non_streaming_server.py +++ b/python-api-examples/non_streaming_server.py @@ -641,7 +641,11 @@ async def process_request( path: str, request_headers: websockets.Headers, ) -> Optional[Tuple[http.HTTPStatus, websockets.Headers, bytes]]: - if "sec-websocket-key" not in request_headers: + if "sec-websocket-key" not in ( + request_headers.headers # For new request_headers + if hasattr(request_headers, "headers") + else request_headers # For old request_headers + ): # This is a normal HTTP request if path == "/": path = "/index.html" diff --git a/python-api-examples/streaming_server.py b/python-api-examples/streaming_server.py index c7c1b8de6..5691f67c3 100755 --- a/python-api-examples/streaming_server.py +++ b/python-api-examples/streaming_server.py @@ -584,7 +584,11 @@ async def process_request( path: str, request_headers: websockets.Headers, ) -> Optional[Tuple[http.HTTPStatus, websockets.Headers, bytes]]: - if "sec-websocket-key" not in request_headers: + if "sec-websocket-key" not in ( + request_headers.headers # For new request_headers + if hasattr(request_headers, "headers") + else request_headers # For old request_headers + ): # This is a normal HTTP request if path == "/": path = "/index.html"