简体   繁体   中英

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

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?

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

json=json.dumps({"parentValue":{"value1":False,"value2":None}})

正如 roganjosh 所建议的,需要的对象上的json.dumps()有效。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM