我设法在 python 中使用 google.cloud.datastore 创建或修改数据存储实体,但是当我在浏览器中登录到我的 Cloud Platform 项目并检查条目时,它的所有属性似乎都已加密(它们看起来像 "Rm9vIEJhcg==" 之类的 - 如果我从浏览器创建它,我可以正常看到)。
我正在使用服务帐户身份的 json 文件进行身份验证:
self.client = datastore.Client()
self.client = self.client.from_service_account_json(cert_file.json)
服务帐户对整个项目具有“编辑”权限。将其更改为“所有者”(这是我用于登录的 gmail 帐户的设置)并不能解决问题。
我这样创建实体:
with self.datastore.client.transaction():
entity = Entity(Key("key", project="project"))
entity["property"] = "data"
self.datastore.client.put(entity)
有什么方法可以使我用 python 库修改的条目可以从浏览器站点读取?
请您参考如下方法:
该值并未真正加密,而是使用 Base64 编码。原因是该值存储为 Blob(原始字节),而不是文本/字符串。控制台以 Base64 格式显示 Blob 字段。值 Rm9vIEJhcg==,当用 Base64 解码时,是 Foo Bar。
本人Python知识不多,看官方的Note documentation :
When saving an entity to the backend, values which are “text” (unicode in Python2, str in Python3) will be saved using the ‘text_value’ field, after being encoded to UTF-8. When retrieved from the back-end, such values will be decoded to “text” again. Values which are “bytes” (str in Python2, bytes in Python3), will be saved using the ‘blob_value’ field, without any decoding / encoding step.
根据您使用的 Python 版本,调整数据的数据类型,问题应该得到解决。
