Skip to content

requests: incorrectly extends callers headers dict #965

@agadsby

Description

@agadsby

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:

if headers is None:
headers = {}

Add

    else:
        headers = headers.copy()

to take a local copy for subsequent use in requests().

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions