kopia lustrzana https://github.com/micropython/micropython-lib
uaiohttpclient: Update example client code.
Signed-off-by: Mark Blakeney <mark.blakeney@bullet-systems.net>pull/764/head
rodzic
05efdd03a7
commit
9ceda53180
|
@ -1,31 +1,16 @@
|
||||||
#
|
#
|
||||||
# uaiohttpclient - fetch URL passed as command line argument.
|
# uaiohttpclient - fetch URL passed as command line argument.
|
||||||
#
|
#
|
||||||
|
import sys
|
||||||
import uasyncio as asyncio
|
import uasyncio as asyncio
|
||||||
import uaiohttpclient as aiohttp
|
import uaiohttpclient as aiohttp
|
||||||
|
|
||||||
|
|
||||||
def print_stream(resp):
|
async def run(url):
|
||||||
print((yield from resp.read()))
|
resp = await aiohttp.request("GET", url)
|
||||||
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)
|
|
||||||
print(resp)
|
print(resp)
|
||||||
yield from print_stream(resp)
|
print(await resp.read())
|
||||||
|
|
||||||
|
|
||||||
import sys
|
|
||||||
import logging
|
|
||||||
|
|
||||||
logging.basicConfig(level=logging.INFO)
|
|
||||||
url = sys.argv[1]
|
url = sys.argv[1]
|
||||||
loop = asyncio.get_event_loop()
|
asyncio.run(run(url))
|
||||||
loop.run_until_complete(run(url))
|
|
||||||
loop.close()
|
|
||||||
|
|
Ładowanie…
Reference in New Issue