Closed
Description
Unfortunately HUE light hubs do not return HTTP responses with the Content-Length
header (!!)
Response._remaining
is based on Content-Length header. This inits with Nonetype
value which causes comparison issues:
>>> resp = requests.get("http://1.2.3.4/api/username/lights/1")
>>> resp.content
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "adafruit_requests.py", line 311, in content
File "adafruit_requests.py", line 365, in iter_content
File "adafruit_requests.py", line 252, in close
TypeError: unsupported types for __gt__: 'NoneType', 'int'
Even when coercing or defaulting Response._remaining
to zero instead, I think all methods now use Response._remaining
so the actual content is never readable or drained properly.
>>> resp = requests.get("http://1.2.3.4/api/username/lights/1")
>>> resp.content
b''
>>> resp = requests.get("http://1.2.3.4/api/username/lights/2")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "adafruit_requests.py", line 632, in get
File "adafruit_requests.py", line 540, in request
File "adafruit_requests.py", line 537, in request
File "adafruit_requests.py", line 459, in _send_request
File "adafruit_requests.py", line 449, in _send
File "adafruit_esp32spi/adafruit_esp32spi_socket.py", line 82, in send
File "adafruit_esp32spi/adafruit_esp32spi.py", line 710, in socket_write
RuntimeError: Failed to send 2 bytes (sent 0)
In version 1.6 it looks like the Content-Length
is used for the content property, but Response.iter_content
does not (It simply streams data). I believe that this is at least part of why it works when interacting with HUE.
Metadata
Metadata
Assignees
Labels
No labels