Skip to content
Beau Barker edited this page Jul 4, 2025 · 4 revisions

Aiohttp client.

import asyncio import logging from aiohttp import ClientSession from jsonrpcclient import Error, Ok, parse, request async def main() -> None: """Handle async request""" async with ClientSession() as session: async with session.post( "http://localhost:5000", json=request("ping") ) as response: parsed = parse(await response.json()) # In Python 3.10+ use `match` syntax here instead of isinstance if isinstance(parsed, Ok): print(parsed.result) elif isinstance(parsed, Error): logging.error(parsed.message) asyncio.get_event_loop().run_until_complete(main())

Reference: JSON-RPC in aiohttp.

Clone this wiki locally