【发布时间】:2017-09-28 10:55:14
【问题描述】:
我有使用 NDB 在标准 GAE 上运行的代码和使用 Google Cloud 数据存储库在灵活环境中运行的代码。两者都访问相同的实体。
我在处理 ndb.JsonProperty 时遇到问题。据我所知,这些属性存储为 blob,因此我尝试使用云库模拟该属性。在存储值之前,我执行以下操作:
value_to_store = json.dumps(value, separators=[',',':'])
value_to_store = base64.b64encode(value_to_store)
当我读取一个属性时则相反:
read_value = base64.b64decode(from_db_value)
read_value = json.loads(read_value)
在这种情况下一切正常:
Insert using NDB ---> Read using Cloud Library
Insert using Cloud Library ---> Read using Cloud Library
但在以下情况下失败:
Insert using Cloud Library --> Read using NDB
存储这些属性以使其与 NDB 兼容的正确方法是什么?
谢谢。
【问题讨论】:
-
好的,使用云库插入的值似乎保存为字符串,而使用 NDB 插入的值是 Blob。所以我只需要弄清楚如何使用云数据存储库将值存储为 Blob
标签: python-2.7 google-app-engine google-cloud-datastore app-engine-ndb app-engine-flexible