-
Notifications
You must be signed in to change notification settings - Fork 37
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for response without Content-Length #123
Conversation
With no |
@anecdata, I was wondering about that too. Looks like the timeout is already handled by the socket itself and is set at the socket creation: On my laptop, reaching the timeout will raise a simple I only tried with a server which has a long initial response time. I'll try to setup a server to see how the Pico W behaves if the server hangs midstream. |
@anecdata I had some fun with building an http.server which spits out its response very slowly (each line of the json response takes longer and longer to be sent): https://gist.github.com/grypoB/0c0cda901c2c2d437924ee36f7641ea9 The results are as follows (I only tried with not chunked responses) if you set a small timeout value in the
And if the servers just keep sending data, on the Pico W it raises a All this is very expected, so everything works just fine with regards to timeouts. |
That sounds good, thank you for testing it out. |
@zvxr Are you able to test this still? |
This might be a cross-dependency issue (running older versions of:) but initial attempt in using that branch:
which eventually leads to
|
@zvxr What version of CircuitPython is loaded (and what board is this)? I think |
@anecdata @zvxr from the CircuitPython changelog, the bytearray.find() was added in the 6.0.0 release:
|
I upgraded to Adafruit CircuitPython 7.3.3 -- my device is an Adafruit Metro M4 Express with samd51j19 Unfortunately it seems to hang on any request through hue. This is the traceback when I interrupt:
Verified with new version of circuitpython (and other deps I upgraded) that requests version 1.6 still works (it's just anything after) |
@zvxr Thank you for the traceback. The default timeout is 60s. Can you try with a shorter timeout? To see if the I had a look at the
@anecdata Hopefully reducing the timeout mitigates the issues for @zvxr, but properly fixing this would require that |
@grypoB I would really like to fix ESP32SPI socket and socketpool.socket have the same behavior as CPython socket.socket. The |
This PR reported to help in the Hue case where there is no |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good to me. Thanks for the fix @grypoB.
I don't have the Hue hardware specifically to test, but I did confirm on a Feather ESP32-S2 TFT that the existing example scripts still work as expected. I also set up a local test server with this very basic implementation I found a gist for: https://gist.github.com/shieldwed/0312c39fa486912060c68bfd314f2393 and modified it to omit the content-length header from the response and verified that this new version of the library handles those responses better than the existing released version.
Updating https://github.com/adafruit/Adafruit_CircuitPython_DisplayIO_Layout to 1.19.14 from 1.19.13: > Merge pull request adafruit/Adafruit_CircuitPython_DisplayIO_Layout#84 from jposada202020/updating_cartesian_widget Updating https://github.com/adafruit/Adafruit_CircuitPython_MiniMQTT to 7.2.0 from 7.1.3: > Merge pull request adafruit/Adafruit_CircuitPython_MiniMQTT#151 from vladak/exp_backoff_pr > Add upload url to release action Updating https://github.com/adafruit/Adafruit_CircuitPython_Requests to 1.13.0 from 1.12.12: > Merge pull request adafruit/Adafruit_CircuitPython_Requests#123 from grypoB/content-length > Add upload url to release action Updating https://github.com/adafruit/Adafruit_CircuitPython_Bundle/circuitpython_library_list.md to NA from NA: > Updated download stats for the libraries
Here is a draft to read full responses that do not provide a Content-Length in the header and are not chunked.
I was porting some working code from MicroPython which used urequests to CircuitPython on a Pico W, and I was sad to see it break because of issue #38.
After some time sifting through the code of both libraries, it seems that the urequest library simply does a
usocket.socket().read()
at line 20, whereas this library only reads a specific number of bytes from the response.So here is my hack that fixes my specific use case while not breaking the unit tests.
If you think it is a good way of fixing issue #38, I'd be happy to add some unit test for it.