psf / requests

A simple, yet elegant, HTTP library.
https://requests.readthedocs.io/en/latest/
Apache License 2.0
52.19k stars 9.33k forks source link

Add Warning for Incorrect Keyword Arguments in POST Requests (e.g., 'header' instead of 'headers') #6792

Closed jsilverman26 closed 3 months ago

jsilverman26 commented 3 months ago

Summary:

When making a POST request using the requests library, passing an incorrect keyword argument (e.g., header instead of headers) does not trigger any error or warning. This can lead to unintended behavior, as the request proceeds without the intended headers being applied.

Problem:

The requests library currently does not validate keyword arguments for correctness. If a user accidentally passes a misspelled argument like header instead of headers, the request will still execute, but the headers will not be set as expected. This lack of validation makes it easy to overlook such errors, leading to potential issues that can be difficult to debug.

Proposed Solution:

Introduce a warning mechanism that alerts the user when an unrecognized keyword argument is passed. This could be implemented as a simple check within the requests functions to identify commonly mistaken keywords like header and issue a warning, helping developers catch such errors early.

Benefit:

Adding this feature would improve the developer experience by reducing the likelihood of subtle bugs caused by incorrect keyword arguments. It would also make the requests library more user-friendly by providing immediate feedback when a common mistake is made.

Additional Context:

This issue was observed during development when a request was made with header instead of headers, causing the request to proceed without applying the necessary headers. A warning in such cases would have saved considerable debugging time.

image

Thank you for considering this enhancement!

github-actions[bot] commented 3 months ago

As described in the template, Requests is not accepting feature requests