首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Python get_iam_policies PUBSUB

Python get_iam_policies PUBSUB
EN

Stack Overflow用户
提问于 2020-11-05 23:03:58
回答 1查看 139关注 0票数 0

我试着运行这段代码并得到这个错误...你知道我该怎么解决这个问题吗?

代码语言:javascript
复制
 from google.cloud import pubsub_v1
 topic_id = 'start-instance-event'
 client = pubsub_v1.PublisherClient(credentials=credentials)
 topic_path = client.topic_path(project_id, topic_id)
 policy = client.get_iam_policy(request={"resource": topic_path})
 print("Policy for topic {}:".format(topic_path))
 for binding in policy.bindings:
    print("Role: {}, Members: {}".format(binding.role, binding.members))

错误:

代码语言:javascript
复制
_InactiveRpcError: <_InactiveRpcError of RPC that terminated with:
    status = StatusCode.PERMISSION_DENIED
    details = "User not authorized to perform this action."
    debug_error_string = "{"created":"@1604588362.110000000","description":"Error received from peer ipv6:[2a00:1450:4007:816::200a]:443","file":"src/core/lib/surface/call.cc","file_line":1062,"grpc_message":"User not authorized to perform this action.","grpc_status":7}"
>

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

PermissionDenied                          Traceback (most recent call last)
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-11-26 08:55:17

由于权限错误,这似乎与权限问题有关。在运行代码之前,您应该尝试使用Setting up authentication。在本documentation中,您将了解如何通过IAM API控制访问。

代码语言:javascript
复制
    from google.cloud import pubsub_v1
    
    # TODO(developer): Choose an existing topic.
    # project_id = "your-project-id"
    # topic_id = "your-topic-id"
    
    client = pubsub_v1.PublisherClient()
    topic_path = client.topic_path(project_id, topic_id)
    
    policy = client.get_iam_policy(request={"resource": topic_path})
    
    print("Policy for topic {}:".format(topic_path))
    for binding in policy.bindings:
        print("Role: {}, Members: {}".format(binding.role, binding.members))
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/64699845

复制
相关文章

相似问题

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