From 235cdca7db3c0377a28d867c61efc1073a2fbefd Mon Sep 17 00:00:00 2001 From: xiayouran Date: Wed, 22 Nov 2023 17:00:09 +0800 Subject: [PATCH] fix func send_json to support chinese --- starlette/testclient.py | 2 +- starlette/websockets.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/starlette/testclient.py b/starlette/testclient.py index a0046f2ff..163e5b67e 100644 --- a/starlette/testclient.py +++ b/starlette/testclient.py @@ -147,7 +147,7 @@ def send_bytes(self, data: bytes) -> None: def send_json(self, data: typing.Any, mode: str = "text") -> None: assert mode in ["text", "binary"] - text = json.dumps(data, separators=(",", ":")) + text = json.dumps(data, separators=(",", ":"), ensure_ascii=False) if mode == "text": self.send({"type": "websocket.receive", "text": text}) else: diff --git a/starlette/websockets.py b/starlette/websockets.py index 859560857..a34bc1339 100644 --- a/starlette/websockets.py +++ b/starlette/websockets.py @@ -168,7 +168,7 @@ async def send_bytes(self, data: bytes) -> None: async def send_json(self, data: typing.Any, mode: str = "text") -> None: if mode not in {"text", "binary"}: raise RuntimeError('The "mode" argument should be "text" or "binary".') - text = json.dumps(data, separators=(",", ":")) + text = json.dumps(data, separators=(",", ":"), ensure_ascii=False) if mode == "text": await self.send({"type": "websocket.send", "text": text}) else: