首页 > 解决方案 > 谷歌云日志在使用 python 时不起作用

问题描述

蟒蛇代码。

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

    loggin.info("error")

追溯:

    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

在这里,我正在尝试使用谷歌日志记录,但我遇到了错误。请看一下

我正在使用 python 执行此操作。生成服务帐户创建是否有任何问题

标签: pythongoogle-cloud-platformgoogle-cloud-storage

解决方案


正如约翰所说,您是否检查过服务帐户是否分配了正确的角色?正如官方文档所说:“使用 Python 的 Cloud Logging 库需要 Google Cloud 上的 IAM Logs Writer 角色。大多数 Google Cloud 环境默认提供此角色”。

另一方面,我有点好奇你使用了“google-cloud-storage”标签,但是你没有提到与它相关的东西。您是否检查过问题是否是因为您没有足够的权限(作为存储管理员)来访问您的存储桶?


推荐阅读