![](/img/trans.png)
[英]Google Cloud Datastore Emulator does not use default credentials
[英]Python: Save data in google cloud datastore emulator
我正试图在本地测试谷歌的云数据存储。 我的测试步骤是:
我按照所有步骤使用本地模拟器
gcloud beta emulators datastore start
gcloud beta emulators datastore env-init
但是,在python中,当使用以下命令访问云数据存储时,它总是将数据直接保存到谷歌云而不是将它们保存到本地模拟器
#Imports the Google Cloud client library
from google.cloud import datastore
# Instantiates a client
datastore_client = datastore.Client()
sample_entry = some_data
# Saves the entity
datastore_client.put(sample_entry)
您似乎无法指定库以使用本地数据存储模拟器,就像它们在Node.js客户端中提供的那样
var datastore = gcloud.datastore({
apiEndpoint: "http://localhost:8380"
});
我的问题是,如何让Google云数据存储区python库使用本地模拟器而不是直接使用云
您需要eval $(gcloud beta emulators datastore env-init)
。
gcloud beta emulators datastore env-init
仅打印设置必要环境变量的命令。
你可以尝试类似的东西
if os.getenv('SERVER_SOFTWARE', '').startswith('Google App Engine/'):
# Production
else:
# Local development server
您可以在此处关注更多内容, https://cloud.google.com/appengine/docs/standard/python/tools/using-local-server
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.