Dataproc python API error permission denied

Viewed 317

I try to create a dataproc cluster via python API, I use authentification with json fle containing credentials.

    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)

I get the following error

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

I don't know if I don't have the correct rights or I have an error in the syntax

2 Answers

I managed to solve the issue with adding the zone when instantiating the client:

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

That error indicates your project cannot use that region. However, I think the issue is in how you specify the Dataproc region as regions/europe-west1-b. Instead, please try europe-west1

Related