requests: stream parameter is noop
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?
requests: incorrectly extends callers headers dict
Using MicroPython v1.24.1 on 2024-11-29; Raspberry Pi Pico W with RP2040
The trivial test program below works correctly on Python but fails on Micropython :
import requests
# test to demonstrate that micropython request incorrectly modifies caller's headers dict
headers = {}
response = requests.get(
url="http://www.google.com",
headers=headers,
data="string",
)
print(headers)
assert headers == {}, "requests returned changed headers to parent"
Fix is equally trivial but my github skills are limited.
After these lines:
https://github.com/micropython/micropython-lib/blob/e4cf09527bce7569f5db742cf6ae9db68d50c6a9/python-ecosys/requests/requests/init.py#L47-L48
Add
else:
headers = headers.copy()
to take a local copy for subsequent use in requests().
I can see this has now been fixed by commit #947. Good work.