Skip to content
This repository has been archived by the owner on Jul 18, 2024. It is now read-only.

Error in WebSocket connection After Setup #218

Open
rajakumartu opened this issue Apr 12, 2023 · 0 comments
Open

Error in WebSocket connection After Setup #218

rajakumartu opened this issue Apr 12, 2023 · 0 comments

Comments

@rajakumartu
Copy link

tests/integ/test_on_events.py F [100%]

=================================== FAILURES ===================================
________________________________ test_listener _________________________________

listener = <function listener.._listener at 0x7fb17542c8b0>
event_bus_name = 'ecommerce-dev'

def test_listener(listener, event_bus_name):
    service_name = "ecommerce.test"
    resource = str(uuid.uuid4())
    event_type = "TestEvent"

    events = boto3.client("events")
  listener(service_name, lambda:
        events.put_events(Entries=[{
            "Time": datetime.datetime.utcnow(),
            "Source": service_name,
            "Resources": [resource],
            "DetailType": event_type,
            "Detail": "{}",
            "EventBusName": event_bus_name
        }]),
        lambda x: (
            x["source"] == service_name and
            x["resources"][0] == resource and
            x["detail-type"] == event_type
        )
    )

tests/integ/test_on_events.py:34:


../shared/tests/integ/fixtures.py:120: in _listener
return asyncio.run(_listen())
../../../.pyenv/versions/3.9.7/lib/python3.9/asyncio/runners.py:44: in run
return loop.run_until_complete(main)
../../../.pyenv/versions/3.9.7/lib/python3.9/asyncio/base_events.py:642: in run_until_complete
return future.result()
../shared/tests/integ/fixtures.py:82: in _listen
async with websockets.connect(listener_api_url, extra_headers=headers) as websocket:
../../../.pyenv/versions/3.9.7/envs/ecommerce-platform/lib/python3.9/site-packages/websockets/legacy/client.py:604: in aenter
return await self
../../../.pyenv/versions/3.9.7/envs/ecommerce-platform/lib/python3.9/site-packages/websockets/legacy/client.py:629: in await_impl
await protocol.handshake(


self = <websockets.legacy.client.WebSocketClientProtocol object at 0x7fb174a82f40>
wsuri = WebSocketURI(secure=True, host='9h9hbtpcok.execute-api.us-east-1.amazonaws.com', port=443, resource_name='/prod/', user_info=None)
origin = None
available_extensions = [<websockets.extensions.permessage_deflate.ClientPerMessageDeflateFactory object at 0x7fb175490460>]
available_subprotocols = None
extra_headers = dict_items([('x-amz-date', '20230412T034636Z'), ('Authorization', 'AWS4-HMAC-SHA256 Credential=ASIAWDQINUE6G47QYUGA/20..._request, SignedHeaders=host;x-amz-date, Signature=ce18176dcee8f032f96066765f50a5372453b8ee6f6a38a88e0a035311e68f21')])

async def handshake(
    self,
    wsuri: WebSocketURI,
    origin: Optional[Origin] = None,
    available_extensions: Optional[Sequence[ClientExtensionFactory]] = None,
    available_subprotocols: Optional[Sequence[Subprotocol]] = None,
    extra_headers: Optional[HeadersLike] = None,
) -> None:
    """
    Perform the client side of the opening handshake.

    :param origin: sets the Origin HTTP header
    :param available_extensions: list of supported extensions in the order
        in which they should be used
    :param available_subprotocols: list of supported subprotocols in order
        of decreasing preference
    :param extra_headers: sets additional HTTP request headers; it must be
        a :class:`~websockets.http.Headers` instance, a
        :class:`~collections.abc.Mapping`, or an iterable of ``(name,
        value)`` pairs
    :raises ~websockets.exceptions.InvalidHandshake: if the handshake
        fails

    """
    request_headers = Headers()

    request_headers["Host"] = build_host(wsuri.host, wsuri.port, wsuri.secure)

    if wsuri.user_info:
        request_headers["Authorization"] = build_authorization_basic(
            *wsuri.user_info
        )

    if origin is not None:
        request_headers["Origin"] = origin

    key = build_request(request_headers)

    if available_extensions is not None:
        extensions_header = build_extension(
            [
                (extension_factory.name, extension_factory.get_request_params())
                for extension_factory in available_extensions
            ]
        )
        request_headers["Sec-WebSocket-Extensions"] = extensions_header

    if available_subprotocols is not None:
        protocol_header = build_subprotocol(available_subprotocols)
        request_headers["Sec-WebSocket-Protocol"] = protocol_header

    if extra_headers is not None:
        if isinstance(extra_headers, Headers):
            extra_headers = extra_headers.raw_items()
        elif isinstance(extra_headers, collections.abc.Mapping):
            extra_headers = extra_headers.items()
        for name, value in extra_headers:
            request_headers[name] = value

    request_headers.setdefault("User-Agent", USER_AGENT)

    self.write_http_request(wsuri.resource_name, request_headers)

    status_code, response_headers = await self.read_http_response()
    if status_code in (301, 302, 303, 307, 308):
        if "Location" not in response_headers:
            raise InvalidHeader("Location")
        raise RedirectHandshake(response_headers["Location"])
    elif status_code != 101:
      raise InvalidStatusCode(status_code)

E websockets.exceptions.InvalidStatusCode: server rejected WebSocket connection: HTTP 403

../../../.pyenv/versions/3.9.7/envs/ecommerce-platform/lib/python3.9/site-packages/websockets/legacy/client.py:388: InvalidStatusCode

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant