使用服务帐户

时间:2017-09-21 14:06:38

标签: python-2.7 google-app-engine google-cloud-platform google-cloud-spanner google-iam

我们已在Google云端控制台上创建了云扳手实例和数据库。

我们正在执行的代码段。

def getDatabaseList(self,):
    try:
        parent = "projects/"+self._PROJECT_NAME + "/instances/" + self._INSTANCE_NAME
        response = self.service.projects().instances().databases().list(parent=parent).execute()
    except Exception, e:
        logging.info("Exception while getDatabaseList %s", e)
        return False
    return response

在上面的代码片段中,self.service是对象googleapiclinet库构建对象。

我们在使用服务帐户ID执行上面的代码段时遇到异常。

Exception while getDatabaseList <HttpError 403 when requesting https://spanner.googleapis.com/v1/projects/<projectName>/instances/<instanceName>/databases?alt=json&key=<APIKEY>

returned "Resource projects/<projectName>/instances/<instanceName> is missing IAM permission: spanner.databases.list.">

参考文件cloud spanner IAM

1 个答案:

答案 0 :(得分:0)

有点晚了,但希望这会有所帮助:您是否正确设置了服务帐户的json文件的路径?我浪费了半天玩权限,直到我发现我只是错过了一个env键。

set export GOOGLE_APPLICATION_CREDENTIALS=/path/to/your/service_account/key.json