Why can't I send `None` as data in a POST request using Python's `requests` library?

后端 未结 3 587
时光说笑
时光说笑 2020-12-19 10:46

It seems that when a key in data has a value of None, the key isn\'t included by requests.

>>> req = requests.Request(\'PO         


        
3条回答
  •  攒了一身酷
    2020-12-19 11:13

    I had the same question few days ago and if you replace data with json it should work for you, as now None will be sent in the body.

    request('POST', 'http://google.com', json=dict(a=None, b=1))
    

提交回复
热议问题