gpt4 book ai didi

python-3.x - Dataproc python API 错误权限被拒绝

转载 作者:行者123 更新时间:2023-12-05 02:10:39 25 4
gpt4 key购买 nike

我尝试通过 python API 创建一个 dataproc 集群,我使用包含凭据的 json 文件进行身份验证。

    app = Flask(__name__)

# Explicitly use service account credentials by specifying the private key
# file.
credentials_gcp =
service_account.Credentials.from_service_account_file('credentials.json')

client = dataproc_v1.ClusterControllerClient(credentials = credentials_gcp)
clustertest = {
"project_id": "xxxx",
"cluster_name": "testcluster",
"config": {}
}

# launch cluster on Dataproc
@app.route('/cluster/<project_id>/<region>/<clustername>', methods=['POST'])
def cluster(project_id, region, clustername):
response = client.create_cluster(project_id, 'regions/europe-west1-b',
clustertest)
response.add_done_callback(callback)
result = response.metadata()
return jsonify(result)

我得到以下错误

google.api_core.exceptions.PermissionDenied: 403 Permission denied on 'locations/regions/europe-west1' (or it may not exist)

不知道是我权限不对还是语法有误

最佳答案

我设法解决了在实例化客户端时添加区域的问题:

    your_region = "europe-west1"
client_cluster = dataproc_v1.ClusterControllerClient(credentials = credentials_gcp, client_options = {'api_endpoint': f'{your_region}-dataproc.googleapis.com:443'})

关于python-3.x - Dataproc python API 错误权限被拒绝,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58536538/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com