How do I pass null as a value in a POST request on python?

Question:

I’m trying to send a POST request with params that contain null values and None just gets ignored. Besides that, I’m unsure about whether or not False is sent as false.

For example:

requests.post("http://myurl.com/address/", data = {"parentValue":{"value1":False,"value2":None}})

and the required params server-side are

{"parentValue":{"value1":false, "value2":null}}

tl;dr: I need false and null on the server side as params from a POST request, how do I send them using Python requests?

Asked By: Ignacio Mora

||

Answers:

As roganjosh suggested, json.dumps() on the object needed, works.

Answered By: Ignacio Mora

rather than using data=simplejson.dumps({"parentValue":{"value1":False,"value2":None}}) you should use

json = {"parentValue":{"value1":False,"value2":None}}