dclaar / purple_air

Code for displaying Air Quality from a Purple Air device
MIT License
6 stars 4 forks source link

crashes on list index out of range #11

Closed dclaar closed 3 years ago

dclaar commented 3 years ago
Traceback (most recent call last):
  File "main.py", line 53, in <module>
  File "main.py", line 41, in main
  File "aqi.py", line 366, in Run
  File "aqi.py", line 361, in Run
  File "aqi.py", line 321, in GetData
  File "aqi.py", line 319, in GetData
  File "m5stickc.py", line 242, in GetURI
  File "m5stickc.py", line 238, in GetURI
  File "nurequests.py", line 108, in request
  File "nurequests.py", line 85, in request
IndexError: list index out of range
dclaar commented 3 years ago

This code is in the m5stack version of urequests, too, but might fail on the redirect:

        s.write(b"\r\n")
        if data:
            s.write(data)

        l = s.readline()
        #print(l)
        l = l.split(None, 2)
        status = int(l[1])  <---

This should be the first line that we get back from the HTTP call [RFC2626[(https://www.w3.org/Protocols/rfc2616/rfc2616-sec6.html#:~:text=6.1%20Status%2DLine,in%20the%20final%20CRLF%20sequence.):

6.1 Status-Line
The first line of a Response message is the Status-Line, consisting of the protocol version followed by a numeric status code and its associated textual phrase, with each element separated by SP characters. No CR or LF is allowed except in the final CRLF sequence.

       Status-Line = HTTP-Version SP Status-Code SP Reason-Phrase CRLF

So this seems mandatory!

dclaar commented 3 years ago

I pushed some protection against this out. Still don't know what is going on.

dclaar commented 3 years ago

Same as issue #14