diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
commit | 26a029d407be480d791972afb5975cf62c9360a6 (patch) | |
tree | f435a8308119effd964b339f76abb83a57c29483 /third_party/python/aiohttp/examples/client_auth.py | |
parent | Initial commit. (diff) | |
download | firefox-upstream/124.0.1.tar.xz firefox-upstream/124.0.1.zip |
Adding upstream version 124.0.1.upstream/124.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'third_party/python/aiohttp/examples/client_auth.py')
-rwxr-xr-x | third_party/python/aiohttp/examples/client_auth.py | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/third_party/python/aiohttp/examples/client_auth.py b/third_party/python/aiohttp/examples/client_auth.py new file mode 100755 index 0000000000..6513de20e5 --- /dev/null +++ b/third_party/python/aiohttp/examples/client_auth.py @@ -0,0 +1,23 @@ +#!/usr/bin/env python3 +import asyncio + +import aiohttp + + +async def fetch(session): + print("Query http://httpbin.org/basic-auth/andrew/password") + async with session.get("http://httpbin.org/basic-auth/andrew/password") as resp: + print(resp.status) + body = await resp.text() + print(body) + + +async def go(loop): + async with aiohttp.ClientSession( + auth=aiohttp.BasicAuth("andrew", "password"), loop=loop + ) as session: + await fetch(session) + + +loop = asyncio.get_event_loop() +loop.run_until_complete(go(loop)) |