I have some simple code to call an api, looping every 5 seconds.
It successfully calls the API 4 times, but crashes after the 4th time. Hardware is a NodeMCU flashed with latest micropython
Here is the code
Code: Select all
import urequests
from machine import Pin
from time import sleep
led = Pin(2, Pin.OUT)
while True:
response = urequests.get('http://jsonplaceholder.typicode.com/albums/1')
if response.status_code == 200:
led.value(not led.value())
sleep(5)
Code: Select all
Traceback (most recent call last):
File "main.py", line 5, in <module>
File "zoomlight.py", line 18, in <module>
File "urequests.py", line 149, in get
File "urequests.py", line 82, in request
OSError: -2
MicroPython v1.12 on 2019-12-20; ESP module with ESP8266
The line numbers dont seem to correspond to the line numbers in the files (I guess due to the imports? Im a bit of a python noob) so its hard to tell whats actually causing the error
thanks for the help.