ureqequests.get - IndexError: list index out of range

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
Post Reply
skywest
Posts: 2
Joined: Sat Feb 20, 2021 8:45 pm

ureqequests.get - IndexError: list index out of range

Post by skywest » Mon Feb 22, 2021 2:05 pm

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
Last edited by jimmo on Wed Feb 24, 2021 12:43 am, edited 1 time in total.
Reason: Add [code] formatting

User avatar
jimmo
Posts: 2244
Joined: Tue Aug 08, 2017 1:57 am
Location: Sydney, Australia
Contact:

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

Post by jimmo » Wed Feb 24, 2021 12:46 am

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?

Post Reply