Page 1 of 1

ureqequests.get - IndexError: list index out of range

Posted: Mon Feb 22, 2021 2:05 pm
by skywest
I have one ESP8266 set up as an access point and can successfully connect to it with phone, tablet, pc etc. It returns a web page with a couple of buttons which turn the led on the AP on or off.

However, if i set up a second ESP8266 as a station, with the code below, it runs fine for a random number of loops then gives this error:

Code: Select all

Traceback (most recent call last):
  File "<stdin>", line 30, in <module>
  File "urequests.py", line 162, in get
  File "urequests.py", line 131, in request
IndexError: list index out of range

Any clues would be welcome as I've spent too long on this already! Here's the code and the Thonny output:

Code: Select all

import network
import urequests
import time
import gc

gc.collect()

print("connecting........")
station = network.WLAN(network.STA_IF)
station.active(True)
station.connect("ESP8266_AP", "telescope")

while station.isconnected() == False:
  pass

print('Connection successful')
print(station.ifconfig())

while True:
    
    gc.collect()
    
    print("ON")
    response = urequests.get("http://192.168.4.1/?dir=OUT")
    print(response.content)
    print(response.status_code)
    response.close()
    
    print("OFF")
    response = urequests.get("http://192.168.4.1/?dir=IN")
    print(response.content)
    print(response.status_code)
    response.close()
----------------------------------------------------------------

Code: Select all

>>> %Run -c $EDITOR_CONTENT
connecting........
Connection successful
('192.168.4.2', '255.255.255.0', '192.168.4.1', '192.168.4.1')
ON
b''
200
OFF
b''
200
ON
b''
200
OFF
Traceback (most recent call last):
  File "<stdin>", line 30, in <module>
  File "urequests.py", line 162, in get
  File "urequests.py", line 131, in request
IndexError: list index out of range

Re: ureqequests.get - IndexError: list index out of range

Posted: Wed Feb 24, 2021 12:46 am
by jimmo
skywest wrote:
Mon Feb 22, 2021 2:05 pm
Any clues would be welcome as I've spent too long on this already!
The first step would be to see what line 131 of urequests.py does.

My copy (https://github.com/micropython/micropyt ... equests.py) doesn't have a line 131 though... where did you get urequests.py from?