【问题标题】:Completion handling in Firestore PythonFirestore Python 中的完成处理
【发布时间】:2018-08-14 01:42:51
【问题描述】:

我是 python 和 firestore 的新手。但我对 Firebase 有一些经验。我浏览了 python 的Firestore doc。我不知道如何查找任务是成功完成还是出现错误。通常其他语言都有完成块。

例如,我想知道以下代码的写入是成功还是错误:

resp = doc_ref.set({
u'first': u'Alan',
u'last': u'Lovelace',
u'born': 1915
})

【问题讨论】:

标签: python flask google-cloud-firestore


【解决方案1】:

您可以查看 reference for firestore python 客户端。它解释了操作返回的结果、可能引发的错误等。

例如,下面是来自reference 的sn-p for Documents-

create(document_data) 在 Firestore 数据库。

参数:document_data (dict) – 要使用的属性名称和值 用于创建文档。返回:对应的写结果 提交的文件。写入结果包含 update_time 字段。

返回类型:google.cloud.firestore_v1beta1.types.WriteResult

引发:冲突 - 如果文档已经存在。

您可以尝试除块来捕获和处理相关情况下的错误。

here 是一个 SO 帖子,解释了什么是 python 等价于快速完成块。

【讨论】:

    猜你喜欢
    • 2020-06-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-03-22
    • 1970-01-01
    相关资源
    最近更新 更多