-
-
Notifications
You must be signed in to change notification settings - Fork 9.3k
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
Add json parameter #2258
Add json parameter #2258
Conversation
"""Sends a POST request. Returns :class:`Response` object. | ||
|
||
:param url: URL for the new :class:`Request` object. | ||
:param data: (optional) Dictionary, bytes, or file-like object to send in the body of the :class:`Request`. | ||
:param json: (optional) json data to send in the body of the :class:`Request`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This would get passed through with the kwargs, right, so I guess this is just so people know about the parameter?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kevinburke yes
@@ -397,7 +402,7 @@ def prepare_headers(self, headers): | |||
else: | |||
self.headers = CaseInsensitiveDict() | |||
|
|||
def prepare_body(self, data, files): | |||
def prepare_body(self, data, files, _json=None): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why the underscore?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Working on changing that already. The problem is that the module json
is imported at the top and needs to be used.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed by aliasing json_dumps = json.dumps
at the top of the module. Not sure I like it, but apparently import semantics are such that requests.compat.json
can't be imported from (e.g., you can't do from .compat.json import dumps
). Can you think of a better solution to avoid the local variable/parameter from shadowing the top-level module name beyond doing from . import compat
and then doing compat.json.dumps
?
- Don't _ prefix json in prepare_body - Don't initialize json to [] - Don't initialize json to {} - Reorder parameters to PreparedRequest.prepare - Remove extra parentheses - Update docstring
@Lukasa @kevinburke care to take another look at this? |
LGTM |
omg I'm so excited ❤️ ✨ 🍰 🌹 🍰 ✨ ❤️ |
@willingc thank you so much for your hard work on this. 🍰 (Those emoji from @kennethreitz are for you ;)) |
Thank you @sigmavirus24 for your support and mentoring 🎸 🌅 🌲 , @Lukasa for the review 🐱 🐈 😸 , and @kennethreitz for the community atmosphere 📷 ✌️ 🎸 |
@willingc thank YOU, and you're welcome :) |
@@ -209,6 +212,7 @@ def __init__(self, | |||
headers=None, | |||
files=None, | |||
data=None, | |||
json=None, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry I'm late to the party, was out - wouldn't this also change the meaning for anyone who creates a Request by hand, eg
params = {'date_created': '1-1-14'}
req = Request('GET', 'http://jsonip.com', {'User-Agent': 'foobar'}, None, {}, params)
where now suddenly params is JSON data?
Closes #2025