urequests
Posted: Thu Oct 06, 2022 8:50 am
Here is a minimal program (I use an esp32) to get some data from an url:
import network
import urequests as requests
ssid = "myWifi"
password = "myPassword"
from machine import Pin
blueled=Pin(2,Pin.OUT)
station = network.WLAN(network.STA_IF)
station.active(True)
station.connect(ssid, password)
i=0
while station.isconnected() == False:
utime.sleep_ms(10)
i=i+1
print(i)
blueled.value(not blueled.value())
pass
print("Connection successful")
res = requests.get(url = "http://worldtimeapi.org/api/timezone/Europe/Paris")
print(res.text)
for i in range(0,10):
blueled.value(not blueled.value())
utime.sleep_ms(50)
Sometimes the program works, sometime it says 'no module urequests', and sometimes it says 'OSError: -202. How can I make it always work.
I find it very strange that the urequests module sometimes is there and sometimes not!?
import network
import urequests as requests
ssid = "myWifi"
password = "myPassword"
from machine import Pin
blueled=Pin(2,Pin.OUT)
station = network.WLAN(network.STA_IF)
station.active(True)
station.connect(ssid, password)
i=0
while station.isconnected() == False:
utime.sleep_ms(10)
i=i+1
print(i)
blueled.value(not blueled.value())
pass
print("Connection successful")
res = requests.get(url = "http://worldtimeapi.org/api/timezone/Europe/Paris")
print(res.text)
for i in range(0,10):
blueled.value(not blueled.value())
utime.sleep_ms(50)
Sometimes the program works, sometime it says 'no module urequests', and sometimes it says 'OSError: -202. How can I make it always work.
I find it very strange that the urequests module sometimes is there and sometimes not!?