Wes*_*sam 2 python google-cloud-datastore google-cloud-platform
根据Google的Cloud Datastore Emulator安装说明,我能够在bash终端窗口中安装和运行模拟器而不会出现问题gcloud beta emulators datastore start --project gramm-id.
我还根据说明在另一个终端设置了环境变量,$(gcloud beta emulators datastore env-init)并验证了它们的定义.
但是,当我运行我的python脚本以使用以下代码将实体添加到本地数据存储区时:
from google.cloud import datastore
print(os.environ['DATASTORE_HOST']) # output: http://localhost:8081
print(os.environ['DATASTORE_EMULATOR_HOST']) # output: localhost:8081
client = datastore.Client('gramm-id')
kind = 'Task'
name = 'simpleTask'
task_key = client.key(kind, name)
task = client.Enity(key=task_key)
task['description'] = 'Buy milk'
client.put(task)
Run Code Online (Sandbox Code Playgroud)
我收到错误:
Traceback (most recent call last):
File "tools.py", line 237, in <module>
client = datastore.Client('gramm-id')
File "/home/.../lib/python3.6/site-packages/google/cloud/datastore/client.py", line 205, in __init__
project=project, credentials=credentials, _http=_http)
... long stack trace ....
File "/home/.../lib/python3.6/site-packages/google/auth/_default.py", line 306, in default
raise exceptions.DefaultCredentialsError(_HELP_MESSAGE)
google.auth.exceptions.DefaultCredentialsError: Could not automatically determine credentials. Please set GOOGLE_APPLICATION_CREDENTIALS or explicitly create credentials and re-run the application. For more information, please see https://developers.google.com/accounts/docs/application-default-credentials.
Run Code Online (Sandbox Code Playgroud)
我认为我不需要创建GCP服务帐户并提供访问凭据以在我的计算机上使用数据存储模拟器.
我的系统:
我错过了什么?
| 归档时间: |
|
| 查看次数: |
783 次 |
| 最近记录: |