![](/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.