Python 3.x 如何从Python 3对Google数据存储执行基于键的查询?

Python 3.x 如何从Python 3对Google数据存储执行基于键的查询?,python-3.x,google-cloud-datastore,Python 3.x,Google Cloud Datastore,我设法与谷歌云数据库建立了连接。现在,我想获得一些实体的密钥/Id。现在我正在执行以下操作: from google.cloud import datastore client = datastore.Client() query = client.query(kind='City') query.key_filter("325899977574122") -> Exception here 我得到“无效密钥:'325899977574122'”。 错误的原因可能是什么?这个Id存

我设法与谷歌云数据库建立了连接。现在,我想获得一些实体的密钥/Id。现在我正在执行以下操作:

from google.cloud import datastore


client = datastore.Client()
query = client.query(kind='City')
query.key_filter("325899977574122") -> Exception here

我得到“无效密钥:'325899977574122'”。
错误的原因可能是什么?这个Id存在,一个城市确实有这个密钥/Id。

看起来它需要的类型是
google.cloud.datastore.key.key

另外,
325899977574122
可能被认为是长时间的

比如说:

client = datastore.Client()
query = client.query(kind='City')
query.key_filter(Key('City', 325899977574122L, project=project)) 
编辑:

此外,如果您试图检索单个id,您可能应该使用以下方法:

按ID获取比执行查询更快

client = datastore.Client()
client.get(Key('City', 325899977574122L, project=project))