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

2

12

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?

Voigt answered 21/11, 2017 at 3:58 Comment(3)
A tool such as fiddler, wireshark, or tcpdump (linux) will allow to to see the exact traffic sent -- so you won't have to guess.Applique
You could try json.dumps() on your data object.Burdened
You can use data=simplejson.dumps({"parentValue":{"value1":False,"value2":None}}).Stucco
V
1

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

Voigt answered 8/1, 2018 at 22:52 Comment(0)
A
0

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

json = {"parentValue":{"value1":False,"value2":None}}
Anglesey answered 26/1, 2023 at 14:29 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.