【问题标题】:Dataproc python API error permission deniedDataproc python API错误权限被拒绝
【发布时间】:2019-10-24 07:46:22
【问题描述】:

我尝试通过 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'(或者它可能不存在)

不知道是我没有正确的权限还是语法有错误

【问题讨论】:

    标签: python-3.x google-cloud-platform google-cloud-dataproc


    【解决方案1】:

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

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

    【讨论】:

      【解决方案2】:

      该错误表明您的项目无法使用该区域。但是,我认为问题在于如何将 Dataproc 区域指定为regions/europe-west1-b。相反,请尝试europe-west1

      【讨论】:

      • 感谢您的帮助
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-07-19
      • 1970-01-01
      • 2020-01-02
      • 2016-09-25
      • 2015-09-16
      • 2012-02-11
      相关资源
      最近更新 更多