Two problems:
except Exception as e:
it is silenced. import asyncio
import logging
import httpx
from httpx_ws import aconnect_ws
from httpx_ws.transport import ASGIWebSocketTransport
from starlette.applications import Starlette
from starlette.routing import WebSocketRoute
from starlette.websockets import WebSocketDisconnect
async def ws_hello(websocket):
try:
await websocket.accept()
await websocket.send_text("Hello World!")
await websocket.receive_text()
except WebSocketDisconnect:
pass
except Exception as e:
logging.exception(e)
app = Starlette(
routes=[
WebSocketRoute("/ws", ws_hello),
],
)
async def main():
async with httpx.AsyncClient(transport=ASGIWebSocketTransport(app)) as client:
async with aconnect_ws("http://server/ws", client) as ws:
message = await ws.receive_text()
assert message == "Hello World!"
asyncio.run(main())
ERROR:root:Expected ASGI message "websocket.receive" or "websocket.disconnect", but got 'websocket.close'
Traceback (most recent call last):
File "main.py", line 16, in ws_hello
await websocket.receive_text()
File "\.venv\Lib\site-packages\starlette\websockets.py", line 118, in receive_text
message = await self.receive()
^^^^^^^^^^^^^^^^^^^^
File "\.venv\Lib\site-packages\starlette\websockets.py", line 49, in receive
raise RuntimeError(
RuntimeError: Expected ASGI message "websocket.receive" or "websocket.disconnect", but got 'websocket.close'
Pay now to fund the work behind this issue.
Get updates on progress being made.
Maintainer is rewarded once the issue is completed.
You're funding impactful open source efforts
You want to contribute to this effort
You want to get funding like this too