← index #777Issue #965
Related · high · value 1.851
QUERY · ISSUE

requests: stream parameter is noop

openby tmpltopened 2023-12-09updated 2023-12-09

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?

CANDIDATE · ISSUE

requests: incorrectly extends callers headers dict

closedby agadsbyopened 2025-01-14updated 2025-03-15

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().

1 comment
agadsby · 2025-03-15

I can see this has now been fixed by commit #947. Good work.

Keyboard

j / / n
next pair
k / / p
previous pair
1 / / h
show query pane
2 / / l
show candidate pane
c
copy suggested comment
r
toggle reasoning
g i
go to index
?
show this help
esc
close overlays

press ? or esc to close

copied