[英]403 permission denied to access AutoML from PubSub
I am trying to build an application using Google Cloud Platform AutoML
using Python
.我正在尝试使用Python
使用Google Cloud Platform AutoML
构建应用程序。 My overall code flow looks like this:我的整体代码流程如下所示:
User Interacts--> data sent to PubSub--> callback invokes my AutoML--> Result用户交互--> 发送到 PubSub 的数据--> 回调调用我的 AutoML--> 结果
The snippet that calls pubsub
looks like this:调用pubsub
的代码片段如下所示:
blob=blob+bytes(doc_type,'utf-8')
publisher.publish(topic,blob)
future=subscriber.subscribe(subscription,callback=callback)
#flash("The object is "+future,'info')
try:
future.result()
except Exception as ex:
subscriber.close()
In PubSub
callback:在PubSub
回调中:
def callback(message):
new_message=message.data
display_name,score=predict_value(new_message,"modelID","projectid",'us-central1')
message.ack()
And my predict_value
gets the model_id
, project id
and compute region
and performs the prediction.我的predict_value
获取model_id
、 project id
和计算region
并执行预测。
When I directly call predict_value
without using PubSub
it is working fine.当我不使用PubSub
直接调用predict_value
,它工作正常。 If I do like this, I am getting the below error:如果我这样做,我会收到以下错误:
google.api_core.exceptions.PermissionDenied: 403 Permission 'automl.models.predict' denied on resource 'projects/projectID/locations/us-central1/models/' (or it may not exist).
Please help me to resolve the issue请帮我解决问题
Thank you so much for all your responses.非常感谢您的所有回复。 I have just fixed the issue using the below snippet example我刚刚使用下面的代码片段示例解决了这个问题
def receive_messages_synchronously(project, subscription_name):
"""Pulling messages synchronously."""
# [START pubsub_subscriber_sync_pull]
# project = "Your Google Cloud Project ID"
# subscription_name = "Your Pubsub subscription name"
subscriber = pubsub_v1.SubscriberClient()
subscription_path = subscriber.subscription_path(
project, subscription_name)
# Builds a pull request with a specific number of messages to return.
# `return_immediately` is set to False so that the system waits (for a
# bounded amount of time) until at lease one message is available.
response = subscriber.pull(
subscription_path,
max_messages=3,
return_immediately=False)
ack_ids = []
for received_message in response.received_messages:
print("Received: {}".format(received_message.message.data))
ack_ids.append(received_message.ack_id)
# Acknowledges the received messages so they will not be sent again.
subscriber.acknowledge(subscription_path, ack_ids)
# [END pubsub_subscriber_sync_pull]
The reason being the subscription that is created uses the pull request.原因是创建的订阅使用拉取请求。 I guess the callback method concept used is mainly for "push" which may be the reason because I didnt give the endpoint and token to publish the message.我猜使用的回调方法概念主要是为了“推送”,这可能是因为我没有提供端点和令牌来发布消息。 Hope what I am guessing is correct.希望我的猜测是正确的。 Let me know your views as well.也让我知道你的看法。
This is likely due to one of two factors:这可能是由于以下两个因素之一造成的:
invalid credentials being used when sending the request to the AutoML API - it is very likely that pubsub executes in other context and can't get the default credentials向 AutoML API 发送请求时使用的凭据无效 - pubsub 很可能在其他上下文中执行并且无法获取默认凭据
invalid model resource name (make sure it is correct) - it should be something like: "projects/12423534/locations/us-central1/models/23432423"无效的模型资源名称(确保它是正确的) - 它应该是这样的:“projects/12423534/locations/us-central1/models/23432423”
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.