我正在尝试使用google-cloud-python库在Dataproc中创建一个集群,然而,当设置region = 'us-central1'时,我得到以下异常:
google.api_core.exceptions.InvalidArgument: 400 Region 'us-central1' is invalid.
Please see https://cloud.google.com/dataproc/docs/concepts/regional-endpoints
for additional information on regional endpoints代码(基于example):
#!/usr/bin/python
from google.cloud import dataproc_v1
client = dataproc_v1.ClusterControllerClient()
project_id = 'my-project'
region = 'us-central1'
cluster = {...}
response = client.create_cluster(project_id, region, cluster)发布于 2018-11-21 04:45:33
Dataproc使用region字段来路由REST请求,但是在gRPC客户端中没有使用该字段(因此出现错误)。
只有global多区域才能通过默认端点访问。要使用区域端点,如us-central1,您必须将该端点配置为在客户端的transport上寻址。
Dataproc区域端点遵循以下模式:<region>-dataproc.googleapis.com:443。region字段应设置为与端点中的区域相同的值。
示例:
#!/usr/bin/python
from google.cloud import dataproc_v1
from google.cloud.dataproc_v1.gapic.transports import cluster_controller_grpc_transport
transport = cluster_controller_grpc_transport.ClusterControllerGrpcTransport(
address='us-central1-dataproc.googleapis.com:443')
client = dataproc_v1.ClusterControllerClient(transport)
project_id = 'my-project'
region = 'us-central1'
cluster = {...}
response = client.create_cluster(project_id, region, cluster)发布于 2018-11-21 04:53:24
类似地,使用google-cloud-java客户端:
ClusterControllerSettings settings =
ClusterControllerSettings.newBuilder()
.setEndpoint("us-central1-dataproc.googleapis.com:443")
.build();
try (ClusterControllerClient clusterControllerClient = ClusterControllerClient.create(settings)) {
String projectId = "my-project";
String region = "us-central1";
Cluster cluster = Cluster.newBuilder().build();
Cluster response =
clusterControllerClient.createClusterAsync(projectId, region, cluster).get();
}发布于 2019-10-04 21:38:40
目前,推荐的更改默认API端点的方式是to use client_options。
client_options (
,google.api_core.client_options.ClientOptions) -客户端选项,用于设置客户端上的用户选项。应通过client_options设置接口端点。
下面是一个从json文件加载凭据的示例(使用f字符串的Python 3.6+语法):
from google.cloud.dataproc_v1 import ClusterControllerClient
client = ClusterControllerClient.from_service_account_file(
service_account_json_path,
client_options={'api_endpoint': f'{your_region}-dataproc.googleapis.com:443'})https://stackoverflow.com/questions/53401219
复制相似问题