我试着运行这段代码并得到这个错误...你知道我该怎么解决这个问题吗?
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))错误:
_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)发布于 2020-11-26 08:55:17
由于权限错误,这似乎与权限问题有关。在运行代码之前,您应该尝试使用Setting up authentication。在本documentation中,您将了解如何通过IAM API控制访问。
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))https://stackoverflow.com/questions/64699845
复制相似问题