micropython-lib icon indicating copy to clipboard operation
micropython-lib copied to clipboard

requests: stream parameter is noop

Open tmplt opened this issue 2 years ago • 0 comments

MicroPython v1.21.0; Raspberry Pi Pico W with RP2040.

requests.request exposes a stream=None parameter:

https://github.com/micropython/micropython-lib/blob/d8e163bb5f3ef45e71e145c27bc4f207beaad70f/python-ecosys/requests/requests/init.py#L36-L46

but it is never functionally used, nor is some iter_content API exposed; the parameter is only forwarded to recursive request calls.

Workaround:

r = requests.get(...)
# sidestep @property content, which just reads socket data into memory until EOF
s = r.raw
r.raw = None
buf = bytearray(1024)
while s.readinto(buf) > 0:
    # handle data in buf (e.g. write to file)

if the above is implemented into some iter_content, is the stream parameter even needed? Am I missing something?

tmplt avatar Dec 09 '23 17:12 tmplt