小编Ami*_*mit的帖子

python中的Google Cloud Datastore超时错误

我在Google Cloud Datastore中有一个表,我在其中存储一个小数据结构,该结构用一个Python服务编写,另一个用另一个Python服务读取.我正在使用gcloud版本0.15.0.这是我用来向GCD写入/读取数据的Python代码:

from gcloud import datastore
import datetime
import json
class GCD(object):
def __init__(self, project_id):
    self.client = datastore.Client(project_id)

def put(self, table, key, data):
    with self.client.transaction():
        entity = datastore.Entity(self.client.key(table, key), exclude_from_indexes=['context'])
        entity.update({'context': json.dumps(data), 'created': datetime.datetime.utcnow(), 'done': True})
        try:
            self.client.put(entity)
        except Exception as e:
            print "GCD save failed with exception: %s" % e
    return None

def get(self, table, key):
    entity_key = self.client.key(table, key)
    entity = None
    try:
        entity = self.client.get(entity_key)
    except Exception as e:
        print "GCD read failed with exception: %s" …
Run Code Online (Sandbox Code Playgroud)

python google-cloud-datastore gcloud-python google-app-engine-python google-cloud-python

5
推荐指数
1
解决办法
591
查看次数