summaryrefslogtreecommitdiffstats
path: root/third_party/python/aiohttp/examples/client_auth.py
diff options
context:
space:
mode:
Diffstat (limited to 'third_party/python/aiohttp/examples/client_auth.py')
-rwxr-xr-xthird_party/python/aiohttp/examples/client_auth.py23
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))