Skip to content

Commit 9ceda53

Browse files
bulletmarkdpgeorge
authored andcommitted
uaiohttpclient: Update example client code.
Signed-off-by: Mark Blakeney <[email protected]>
1 parent 05efdd0 commit 9ceda53

File tree

1 file changed

+5
-20
lines changed

1 file changed

+5
-20
lines changed

micropython/uaiohttpclient/example.py

+5-20
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,16 @@
11
#
22
# uaiohttpclient - fetch URL passed as command line argument.
33
#
4+
import sys
45
import uasyncio as asyncio
56
import uaiohttpclient as aiohttp
67

78

8-
def print_stream(resp):
9-
print((yield from resp.read()))
10-
return
11-
while True:
12-
line = yield from resp.readline()
13-
if not line:
14-
break
15-
print(line.rstrip())
16-
17-
18-
def run(url):
19-
resp = yield from aiohttp.request("GET", url)
9+
async def run(url):
10+
resp = await aiohttp.request("GET", url)
2011
print(resp)
21-
yield from print_stream(resp)
12+
print(await resp.read())
2213

2314

24-
import sys
25-
import logging
26-
27-
logging.basicConfig(level=logging.INFO)
2815
url = sys.argv[1]
29-
loop = asyncio.get_event_loop()
30-
loop.run_until_complete(run(url))
31-
loop.close()
16+
asyncio.run(run(url))

0 commit comments

Comments
 (0)