python - Firestore : REST API runQuery method expects wrong parent path pattern

标签 python rest google-cloud-firestore

我正在尝试使用 Firestore REST API 执行一个简单的查询。

根据 Google App Engine 标准,我无法使用尚未与 GAE 标准兼容的 google-cloud-firestore 客户端。相反,对于其他 Google API,我使用 google-api-python-client。

这是我初始化服务的方式:

service = build('firestore', 'v1beta1', credentials=_credentials)

完成后,我将以这种方式执行查询:

query = { "structuredQuery":
          {
            "from": [{ "collectionId": "mycollection" }],
            "where": {
              "fieldFilter":
              {
                "field": { "fieldPath": "myfield" },
                "op": "EQUAL",
                "value": { "stringValue": "myvalue" }
              }
            }
          }
        }

response = service.projects().databases().documents().runQuery(
            parent='projects/myprojectid/databases/(default)/documents',
            body=query).execute()

这会返回一个非常明确的错误:

TypeError: Parameter "parent" value "projects/myprojectid/databases/(default)/documents" does not match the pattern "^projects/[^/]+/databases/[^/]+/documents/[^/]+/.+$"

这显然是真的。我的观点是文档清楚地表明这应该是一个可接受的值:

The parent resource name. In the format: projects/{project_id}/databases/{database_id}/documents or projects/{project_id}/databases/{database_id}/documents/{document_path}. For example: projects/my-project/databases/my-database/documents or projects/my-project/databases/my-database/documents/chatrooms/my-chatroom (string)

使用 API Explorer(或 curl)执行相同的查询工作正常并且返回预期结果。 (即使 API Explorer 确实声明父参数与预期模式不匹配)。

API Explorer pattern not matching

似乎发现文档(由 google-api-python-client 使用)对父参数强制执行此模式检查,但关联的正则表达式实际上不允许唯一似乎有效的父路径(projects/myprojectid/databases/(默认)/documents)。

我尝试使用不同的模式路径,如 projects/myprojectid/databases/(default)/documents/*/**,这使得查询运行正常但不返回任何结果。

有人遇到同样的问题还是我做错了什么? 我能想到的唯一解决方法是在不使用 google-api-python-client 的情况下直接向正确的 url 发出请求,但这意味着我必须手动处理身份验证过程,这很痛苦。

感谢您提供的任何帮助!

最佳答案

google-cloud-firestore 现在与标准 App Engine 兼容。

https://cloud.google.com/firestore/docs/quickstart-servers

关于python - Firestore : REST API runQuery method expects wrong parent path pattern,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49899100/

相关文章:

reactjs - 为什么我的组件的基于 redux 的 Prop 没有更新?

python - 等级不匹配 : Rank of labels (received 2) should equal rank of logits minus 1 (received 2)

Python:整数到 Base 32 十六进制(又名。Triacontakaidecimal)

java - GSON 如何决定它在反序列化过程中使用哪个 TypeAdapter?

rest - 在浏览器中发送之前编辑请求

php - Rest Api 的服务器端实现

swift - Firebase Firestore "Could not build module ' nanopb'

firebase - 我想在get函数中获取用户ID

python - 从 spaCy 中的词根 (lemma) 和词性 (POS) 标签获取完全形成的词 "text"

python - 无法安装 TensorFlow Python 依赖项