-
-
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
sending post request data nested object #2885
Comments
What are you expecting the result to be here? |
the post data that send become config : data instead of the full object |
I'm sorry, I wasn't clear enough. When you use the |
If I urlencode the payload it appear like this
which is what should I get on the server |
So you literally want to represent the config as a urlencoded JSON string? |
Ah sorry shouldn't use urlencode, in php they have http_build_query that convert the payload become like this
|
@wiryono That does not match what the urlencoded payload you copied decodes to. In fact, your urlencoded payload corresponds to import json
payload = {
"config": json.dumps({
"data" : "test"
})
}
r = request.post('http://httpbin.org/post', data=payload)
print(r.text) That will work appropriately. |
Ok, so to represent that in requests you want to use: payload = {
"config[data]": 'test',
} There is no consistent, standardised way to represent nested data in form-encoding, and PHP just happily invented one. Requests doesn't guess what you want here, you need to come up with a conversion function yourself I'm afraid. |
See also requests/toolbelt#45 (which I hope to have time to tackle soon). |
The solution is non-obvious, but all you have to do is change the r = request.post('http://httpbin.org/post', json=payload) It's not clear to me why the two arguments exist when they seem to be functionally identical. At least, a warning should be given to the user when trying to send a nested dictionary with the |
They're not functionally identical in the slightest, otherwise both would just work. Please read the documentation. |
Unable to send post data from nested object, some of the data is truncated
The text was updated successfully, but these errors were encountered: