1# Test uasyncio.open_connection() and stream readline() 2 3try: 4 import uasyncio as asyncio 5except ImportError: 6 try: 7 import asyncio 8 except ImportError: 9 print("SKIP") 10 raise SystemExit 11 12 13async def http_get_headers(url): 14 reader, writer = await asyncio.open_connection(url, 80) 15 16 print("write GET") 17 writer.write(b"GET / HTTP/1.0\r\n\r\n") 18 await writer.drain() 19 20 while True: 21 line = await reader.readline() 22 line = line.strip() 23 if not line: 24 break 25 if ( 26 line.find(b"Date") == -1 27 and line.find(b"Modified") == -1 28 and line.find(b"Server") == -1 29 ): 30 print(line) 31 32 print("close") 33 writer.close() 34 await writer.wait_closed() 35 print("done") 36 37 38asyncio.run(http_get_headers("micropython.org")) 39