[英]upload .json file to firebase database using python
我想将整个 JSON 文件上传到我的 Firebase 数据库,但我无法让它运行。 我是 Python 和 Firebase 的新手。
到目前为止,这是我的代码:
import firebase_admin
from firebase_admin import credentials
from firebase_admin import db
import json
import requests
from pprint import pprint
cred = credentials.Certificate("path/to/serviceAccountKey.json")
firebase_admin.initialize_app(cred)
with open ('/Users/name/Desktop/Test.json') as data_file: data = json.load(data_file)
jsondata = json.dumps('/Users/name/Desktop/Test.json')
requests.put(url="https://myapp.firebaseio.com/", json= jsondata)
我收到一个错误: <响应 [400]>
您执行实际写入操作的代码:
requests.put(url="https://myapp.firebaseio.com/", json= jsondata)
This code does not in any way use the Admin SDK, but instead writes directly to the REST API of the Firebase Realtime Database.
如果您想使用 REST API 编写,这是可能的,但您需要:
确保您的 REST 调用已通过身份验证,如有关身份验证 REST 请求的文档中所示。
使用以 .json 结尾的.json
以确保您的通话结束至 REST ZDB97427114CA3ACE6D40。 所以:
requests.put(url="https://myapp.firebaseio.com/.json", json= jsondata)
是的, /.json
末尾那个/.json是正常的。
Alternatively you can continue to use the Admin SDK to write the data , but in that case you'll need to read and parse the JSON into your code, and send it to the database as a JavaScript object, as shown in the documentation on saving管理员 SDK 的数据。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.