Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

requests: incorrectly extends callers headers dict #965

Open
agadsby opened this issue Jan 14, 2025 · 0 comments
Open

requests: incorrectly extends callers headers dict #965

agadsby opened this issue Jan 14, 2025 · 0 comments

Comments

@agadsby
Copy link

agadsby commented Jan 14, 2025

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

@agadsby agadsby changed the title resuests: incorrectly extends callers headers dict requests: incorrectly extends callers headers dict Jan 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant