我正在使用 Datastore Emulator 和Datastore-Python-Client-Library在本地运行以下 Python 代码
# Imports the Google Cloud client library
from google.cloud import datastore
# Instantiates a client
datastore_client = datastore.Client()
# The kind for the new entity
kind = 'Task'
# The name/ID for the new entity
name = 'sampletask1'
# The Cloud Datastore key for the new entity
task_key = datastore_client.key(kind, name)
# Prepares the new entity
task = datastore.Entity(key=task_key)
task['description'] = 'Buy milk'
# Saves the entity
datastore_client.put(task)
print('Saved {}: {}'.format(task.key.name, task['description']))
如果put
操作失败(假设 Datastore Emulator 未启动),如何获取错误值和操作失败的消息?
目前,该put
操作正在成功执行,并且没有引发错误消息或异常。