MCPcopy
hub / github.com/aio-libs/aiohttp / set_token

Function set_token

docs/code/client_middleware_cookbook.py:98–104  ·  view source on GitHub ↗
(session: ClientSession, event: asyncio.Event)

Source from the content-addressed store, hash-verified

96
97async def token_refresh_preemptively_example() -> None:
98 async def set_token(session: ClientSession, event: asyncio.Event) -> None:
99 while True:
100 async with session.post("/refresh") as resp:
101 token = await resp.json()
102 session.headers["Authorization"] = f"Bearer {token['auth']}"
103 event.set()
104 await asyncio.sleep(token["valid_duration"])
105
106 @asynccontextmanager
107 async def auto_refresh_client() -> AsyncIterator[ClientSession]:

Callers 1

auto_refresh_clientFunction · 0.85

Calls 2

postMethod · 0.45
jsonMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…