MCPcopy
hub / github.com/encode/starlette / receive_json

Method receive_json

starlette/websockets.py:130–142  ·  starlette/websockets.py::WebSocket.receive_json
(self, mode: str = "text")

Source from the content-addressed store, hash-verified

128 return cast(bytes, message[class="st">"bytes"])
129
130 async def receive_json(self, mode: str = class="st">"text") -> Any:
131 if mode not in {class="st">"text", class="st">"binary"}:
132 raise RuntimeError(&class="cm">#x27;The class="st">"mode" argument should be class="st">"text" or class="st">"binary".')
133 if self.application_state != WebSocketState.CONNECTED:
134 raise RuntimeError(&class="cm">#x27;WebSocket is not connected. Need to call class="st">"accept" first.')
135 message = await self.receive()
136 self._raise_on_disconnect(message)
137
138 if mode == class="st">"text":
139 text = message[class="st">"text"]
140 else:
141 text = message[class="st">"bytes"].decode(class="st">"utf-8")
142 return json.loads(text)
143
144 async def iter_text(self) -> AsyncIterator[str]:
145 try:

Callers 15

iter_jsonMethod · 0.95
test_websocket_urlFunction · 0.95
appFunction · 0.95
test_websocket_headersFunction · 0.95
test_websocket_portFunction · 0.95
test_websocket_iter_jsonFunction · 0.95
asgiFunction · 0.95

Calls 3

receiveMethod · 0.95
_raise_on_disconnectMethod · 0.95
decodeMethod · 0.80

Tested by 15

test_websocket_urlFunction · 0.76
appFunction · 0.76
test_websocket_headersFunction · 0.76
test_websocket_portFunction · 0.76
test_websocket_iter_jsonFunction · 0.76
asgiFunction · 0.76
test_websocket_stateFunction · 0.36