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?
Request modifies header argument
Port, board and/or hardware
RP2040
MicroPython version
MicroPython v1.24.1 on 2024-11-29; Raspberry Pi Pico W with RP2040
Reproduction
Replace ssid / psk and run the code
import network
import requests
import time
def do_connect():
import network
sta_if = network.WLAN(network.WLAN.IF_STA)
if not sta_if.isconnected():
print('connecting to network...')
sta_if.active(True)
sta_if.connect("SSID", "PSK")
while not sta_if.isconnected():
pass
print('network config:', sta_if.ipconfig('addr4'))
do_connect()
HEADERS = {"X-Api-Key": "foobar"}
print(HEADERS)
requests.request(method = "GET", url = "https://postman-echo.com/get", headers = HEADERS, timeout=2)
print(HEADERS)
Expected behaviour
Expected output (working with MicroPython v1.23.0 on 2024-06-02; Raspberry Pi Pico W with RP2040)
{'X-Api-Key': 'foobar'}
{'X-Api-Key': 'foobar'}
Observed behaviour
{'X-Api-Key': 'foobar'}
{'Host': 'postman-echo.com', 'X-Api-Key': 'foobar', 'Connection': 'close'}
Additional Information
No, I've provided everything above.
Code of Conduct
Yes, I agree