错误调用来自Python后端的Google Vertex AI端点
我正在尝试将HTTP POST请求发送到我的Google Vertex AI端点进行预测。尽管我确实在请求标题中设置了携带者令牌,但是请求仍然失败,以下错误:
{
"error": {
"code": 401,
"message": "Request had invalid authentication credentials. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project.",
"status": "UNAUTHENTICATED",
"details": [
{
"@type": "type.googleapis.com/google.rpc.ErrorInfo",
"reason": "ACCESS_TOKEN_TYPE_UNSUPPORTED",
"metadata": {
"service": "aiplatform.googleapis.com",
"method": "google.cloud.aiplatform.v1.PredictionService.Predict"
}
}
]
}
}
由于我是从Python后端进行此通话,因此我不确定消息中建议的OAuth 2是否是明智的,并且适用的选择。
该模型已经在顶点AI上部署和端点测试,并且效果很好。我要做的是使用Postman通过HTTP POST请求发送相同的预测任务,这就是失败的。
请求URL看起来像这样:
https://[LOCATION]-aiplatform.googleapis.com/v1/projects/[PROJECT ID]/locations/[LOCATION]/endpoints/[ENDPOINT ID]:predict
在POTMAN授权选项卡和请求主体中设置的实例中设置了令牌承载者的位置。
I am trying to send an http post request to my google vertex ai endpoint for prediction. Though I do set the Bearer Token in the request header, the request still fails with the below error:
{
"error": {
"code": 401,
"message": "Request had invalid authentication credentials. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project.",
"status": "UNAUTHENTICATED",
"details": [
{
"@type": "type.googleapis.com/google.rpc.ErrorInfo",
"reason": "ACCESS_TOKEN_TYPE_UNSUPPORTED",
"metadata": {
"service": "aiplatform.googleapis.com",
"method": "google.cloud.aiplatform.v1.PredictionService.Predict"
}
}
]
}
}
Since I am making this call from a python backend, I'm not sure if OAuth 2 as suggested in the message would be wise and applicable choice.
The model is already deployed and endpointed test on vertex ai and it worked fine. What I am trying to do is send same prediction task via an http post request using postman and this is what failed.
The request url looks like this:
https://[LOCATION]-aiplatform.googleapis.com/v1/projects/[PROJECT ID]/locations/[LOCATION]/endpoints/[ENDPOINT ID]:predict
Where token bearer is set in the potman authorization tab and instance set in request body.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我通常以这种方式调用顶点AI端点:
在这里,您根据需要编码输入。
检查输入类型的模型签名:
然后
根据提交到顶点AI端点的输入的类型(整数,数组,字符串,图像)调用端点,您可能必须更改编码。
I usually call Vertex AI endpoint this way:
Here, you encode the input according to your needs.
Check the model signature for the input type:
Then call the endpoint
According to the type of the input you are submitting to Vertex AI endpoint (integer, array, string, image), you may have to change the encoding.
如果您不想在提出http post请求时使用OAuth 2.0进行身份验证,则可能需要使用 application默认凭据。在此文档>通过环境变量传递凭据。
If you don't want to use oAuth 2.0 for authentication when making http post request, you may want to use Application Default Credentials. In this documentation you can follow the step by step on getting service account key to passing credentials via environment variable.
您可以尝试以下操作:
导入子过程
导入基础64
导入请求
导入JSON
应该在您发送请求的计算机上配置GCLOUD配置的FF(可以通过使用GCLOUD INIT来执行此操作),并具有访问顶点预测的权限。
Can you try following:
import subprocess
import base64
import requests
import json
It should work ff you have gcloud configured (you can do this by using gcloud init) on the machine you are sending request from and have permissions to access Vertex Prediction.