我正在使用 requests
模块在 Firebase 中获取和设置数据。假设我有一个现有的火力基地,http://mytest.firebaseio.com ,看起来像这样
|somewhere
|--test1
|--exists: 1
我想向其中添加数据,所以它看起来像:
|somewhere
|--test1
|--exists: 1
|--arrived: 1
我的直觉是使用put()
,例如:
r = requests.put('http://mytest.firebaseio.com/test1.json',data='{"arrived":1}')
但这会导致删除除了添加arrived: 1
之外的exists: 1
,例如:
|somewhere
|--test1
|--arrived: 1
如何添加 arrived: 1
而不删除 exists: 1
?
最佳答案
来自docs :
You can update specific children at a location without overwriting existing data with a PATCH request. Named children in the data being written with PATCH will be written, but omitted children will not be deleted. This is equivalent to the update( ) function.
所以你想使用 requests.patch()
而不是 requests.put()
。
关于python - 如何使用 requests、Python 和 Firebase 添加数据而不是替换数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22430619/