如何在数据存储区python中检查Put操作是否成功

问题描述

我正在使用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操作失败(假设数据存储模拟器未启动),如何获取错误值和操作失败的消息?

当前,put操作正在成功执行,并且未引发任何错误消息或异常。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)