1

from the requests documentation :

Remove a Value From a Dict Parameter

Sometimes you’ll want to omit session-level keys from a dict parameter. To do this, you simply set that key’s value to None in the method-level parameter. It will automatically be omitted.

I need the data with key's value as None to take the Json value null instead of being removed. Is it possible ?

edit : This seems to happen with my request data keys. While they are not session-level the behaviour of removing is still the same.

1 Answer 1

6

There is no session-level JSON parameter, so the merging rules don't apply.

In other words, the json keyword argument to the session.request() method is passed through unchanged, None values in that structure do not result in keys being removed.

The same applies to data, there is no session-level version of that parameter, no merging takes place. If data is set to a dictionary, any keys whose value is set to None are ignored. Set the value to '' if you need those keys included with an empty value.

The rule does apply when merging headers, params, hooks and proxies.

Sign up to request clarification or add additional context in comments.

4 Comments

Indeed, I messed up between session-leveled keys and my datas keys! question is edited
@paulc: data is not being merged; instead, keys whose values are set to None are ignored. Use an empty string instead if you need the key to show up with no value.
@paulc: but setting data to a dictionary has nothing to do with JSON data, there is no concept of null in application/x-www-form-urlencoded or multipart/form-data encodings.
Thanks for the enlightenments! Although I can seem to put null data through the django rest framework api I'm using, it seems to be cheating somewhere. I'll have to see on this side. Found a related thread [link]groups.google.com/forum/#!topic/django-rest-framework/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.