From 9ceda531804e20374db7e1cfdcada2318498bb14 Mon Sep 17 00:00:00 2001 From: Mark Blakeney Date: Wed, 8 Nov 2023 08:16:05 +1000 Subject: [PATCH] uaiohttpclient: Update example client code. Signed-off-by: Mark Blakeney --- micropython/uaiohttpclient/example.py | 25 +++++-------------------- 1 file changed, 5 insertions(+), 20 deletions(-) diff --git a/micropython/uaiohttpclient/example.py b/micropython/uaiohttpclient/example.py index 5c03ee2..d265c9d 100644 --- a/micropython/uaiohttpclient/example.py +++ b/micropython/uaiohttpclient/example.py @@ -1,31 +1,16 @@ # # uaiohttpclient - fetch URL passed as command line argument. # +import sys import uasyncio as asyncio import uaiohttpclient as aiohttp -def print_stream(resp): - print((yield from resp.read())) - return - while True: - line = yield from resp.readline() - if not line: - break - print(line.rstrip()) - - -def run(url): - resp = yield from aiohttp.request("GET", url) +async def run(url): + resp = await aiohttp.request("GET", url) print(resp) - yield from print_stream(resp) + print(await resp.read()) -import sys -import logging - -logging.basicConfig(level=logging.INFO) url = sys.argv[1] -loop = asyncio.get_event_loop() -loop.run_until_complete(run(url)) -loop.close() +asyncio.run(run(url))