google cloud logging not working while working with python

python code.

    import google.cloud.logging
    client = google.cloud.logging.Client.from_service_account_json("file.config")
    client.setup_logging()
    import logging

    loggin.info("error")

traceback:

    Traceback (most recent call last):
    File "/Users/soubhagyapradhan/Desktop/upwork/baby/data-science/env/lib/python3.8/site-packages/google/api_core/grpc_helpers.py", line 57, in error_remapped_callable
        return callable_(*args, **kwargs)
    File "/Users/soubhagyapradhan/Desktop/upwork/baby/data-science/env/lib/python3.8/site-packages/grpc/_channel.py", line 923, in __call__
        return _end_unary_response_blocking(state, call, False, None)
    File "/Users/soubhagyapradhan/Desktop/upwork/baby/data-science/env/lib/python3.8/site-packages/grpc/_channel.py", line 826, in _end_unary_response_blocking
        raise _InactiveRpcError(state)
    grpc._channel._InactiveRpcError: <_InactiveRpcError of RPC that terminated with:
        status = StatusCode.PERMISSION_DENIED
        details = "The caller does not have permission"
        debug_error_string = "{"created":"@1612798593.245379000","description":"Error received from peer ipv4:142.250.71.42:443","file":"src/core/lib/surface/call.cc","file_line":1062,"grpc_message":"The caller does not have permission","grpc_status":7}"
    >

    The above exception was the direct cause of the following exception:

    Traceback (most recent call last):
    File "/Users/soubhagyapradhan/Desktop/upwork/baby/data-science/env/lib/python3.8/site-packages/google/cloud/logging/handlers/transports/background_thread.py", line 123, in _safely_commit_batch
        batch.commit()
    File "/Users/soubhagyapradhan/Desktop/upwork/baby/data-science/env/lib/python3.8/site-packages/google/cloud/logging/logger.py", line 383, in commit
        client.logging_api.write_entries(entries, **kwargs)
    File "/Users/soubhagyapradhan/Desktop/upwork/baby/data-science/env/lib/python3.8/site-packages/google/cloud/logging/_gapic.py", line 121, in write_entries
        self._gapic_api.write_log_entries(
    File "/Users/soubhagyapradhan/Desktop/upwork/baby/data-science/env/lib/python3.8/site-packages/google/cloud/logging_v2/gapic/logging_service_v2_client.py", line 476, in write_log_entries
        return self._inner_api_calls["write_log_entries"](
    File "/Users/soubhagyapradhan/Desktop/upwork/baby/data-science/env/lib/python3.8/site-packages/google/api_core/gapic_v1/method.py", line 145, in __call__
        return wrapped_func(*args, **kwargs)
    File "/Users/soubhagyapradhan/Desktop/upwork/baby/data-science/env/lib/python3.8/site-packages/google/api_core/retry.py", line 281, in retry_wrapped_func
        return retry_target(
    File "/Users/soubhagyapradhan/Desktop/upwork/baby/data-science/env/lib/python3.8/site-packages/google/api_core/retry.py", line 184, in retry_target
        return target()
    File "/Users/soubhagyapradhan/Desktop/upwork/baby/data-science/env/lib/python3.8/site-packages/google/api_core/timeout.py", line 214, in func_with_timeout
        return func(*args, **kwargs)
    File "/Users/soubhagyapradhan/Desktop/upwork/baby/data-science/env/lib/python3.8/site-packages/google/api_core/grpc_helpers.py", line 59, in error_remapped_callable
        six.raise_from(exceptions.from_grpc_error(exc), exc)
    File "<string>", line 3, in raise_from
    google.api_core.exceptions.PermissionDenied: 403 The caller does not have permission

Here i am trying to use google logging, But i am getting above error. Please take a look

I am doing this using python. Is there any issue on generating service account creation

Upvotes: 3

Views: 2023

Answers (2)

Dr. Fabien Tarrade
Dr. Fabien Tarrade

Reputation: 1696

I was using :

 client = google.cloud.logging.Client()

(not ".from_service_account_json")

and I was getting the exact same error message. I also had the proper role roles/logging.logWriter. I am using using cloud-logging 2.6.0

I found that when I ran the code above in Vertex AI training job, if I don't create a client using my project_id in the following way:

 client = google.cloud.logging.Client(project=<user project number>)

then google.cloud.logging use some kind of dummy project_id i.e "i285ca2410679d8f1p-tp" which don't have the necessay access. Putting my project_id and all the error messages are then gone.

Upvotes: 2

Samuel Romero
Samuel Romero

Reputation: 1253

As John said, have you checked if the Service Account has the proper role assigned? As the official documentation says: "Using Cloud Logging library for Python requires the IAM Logs Writer role on Google Cloud. Most Google Cloud environments provide this role by default".

On the other hand, I am bit curious you used the "google-cloud-storage" tag, however you are not mention something related to it. Have you checked if the issue is because you do not have the enough permissions (As Storage Admin) to access your bucket?

Upvotes: 1

Related Questions