gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-05 07:34:50 24 4
gpt4 key购买 nike

我正在尝试使用 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com