importnetworkimportsecretsfromutimeimportsleep,ticks_ms,ticks_diffimporturequestswlan=network.WLAN(network.STA_IF)wlan.active(True)wlan.connect(secrets.SSID,secrets.PASSWORD)start=ticks_ms()# start a millisecond counterastronauts=urequests.get("http://api.open-notify.org/astros.json").json()delta=ticks_diff(ticks_ms(),start)number=astronauts['number']print('There are',number,'astronauts in space.')foriinrange(number):print(i+1,astronauts['people'][i]['name'])print("HTTP GET Time in milliseconds:",delta)
Returns:
1 2 3 4 5 6 7 8 9101112
There are 10 astronauts in space.
1 Oleg Artemyev
2 Denis Matveev
3 Sergey Korsakov
4 Kjell Lindgren
5 Bob Hines
6 Samantha Cristoforetti
7 Jessica Watkins
8 Cai Xuzhe
9 Chen Dong
10 Liu Yang
HTTP GET Time in milliseconds: 786