首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用python时,google云日志记录不起作用

使用python时,google云日志记录不起作用
EN

Stack Overflow用户
提问于 2021-02-08 23:39:52
回答 2查看 254关注 0票数 2

python代码。

代码语言:javascript
复制
    import google.cloud.logging
    client = google.cloud.logging.Client.from_service_account_json("file.config")
    client.setup_logging()
    import logging

    loggin.info("error")

回溯:

代码语言:javascript
复制
    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

在这里,我试图使用google日志,但我得到了上面的错误。请看一看

我正在使用python来做这件事。在生成服务帐户创建时是否有任何问题

EN

回答 2

Stack Overflow用户

发布于 2021-02-09 04:27:16

正如John所说,您是否检查过服务帐户是否分配了适当的角色?正如official documentation所说:“使用Python的云日志库需要Google Cloud上的IAM Logs Writer角色。大多数Google Cloud环境默认提供此角色。”

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

票数 1
EN

Stack Overflow用户

发布于 2021-09-11 14:41:48

我使用的是:

代码语言:javascript
复制
 client = google.cloud.logging.Client()

(不是".from_service_account_json")

我也收到了完全相同的错误信息。我也有合适的角色roles/logging.logWriter。我正在使用cloud-logging 2.6.0

我发现当我在顶点AI训练任务中运行上面的代码时,如果我不使用我的project_id以下面的方式创建一个客户端:

代码语言:javascript
复制
 client = google.cloud.logging.Client(project=<user project number>)

然后google.cloud.logging使用某种虚拟project_id,即"i285ca2410679d8f1p-tp“,它没有必要的访问权限。放入我的project_id,所有的错误信息都会消失。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/66104699

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档