Skip to content

Commit 9ceda53

Browse files
bulletmarkdpgeorge
authored andcommitted
uaiohttpclient: Update example client code.
Signed-off-by: Mark Blakeney <mark.blakeney@bullet-systems.net>
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

Lines changed: 5 additions & 20 deletions
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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy