为什么在 Vertex AI 示例中 Cloud Function 无法访问元数据服务器?

问题描述

我关注了this Vertex AI tutorial。但是,在最后一步,当 Cloud Function 调用预测端点时,它会失败。

这意味着它甚至无法访问元数据服务器。即,不是权限失败(尽管我确实检查了 myproject@appspot.gserviceaccount.com 服务帐户确实具有指定的项目编辑器角色)。严格来说,这也是函数和 IAM 中的错误,而不是 Vertex.AI 或其他 ML 系统中的错误

这里出了什么问题?

Function execution took 673 ms,finished with status code: 500
Prediction request Failed: <class 'google.api_core.exceptions.ServiceUnavailable'>: 503 Getting Metadata from plugin Failed with error: ("Failed to retrieve http://Metadata.google.internal/computeMetadata/v1/instance/service-accounts/myproject@appspot.gserviceaccount.com/token?scopes=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fcloud-platform from the Google Compute EngineMetadata service. Status: 500 Response:\nb'Could not fetch URI /computeMetadata/v1/instance/service-accounts/myproject@appspot.gserviceaccount.com/token?scopes=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fcloud-platform\\n'",<google.auth.transport.requests._Response object at 0x3e095a9f4c50>)
google.auth.exceptions.RefreshError: ("Failed to retrieve http://Metadata.google.internal/computeMetadata/v1/instance/service-accounts/myproject@appspot.gserviceaccount.com/token?scopes=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fcloud-platform from the Google Compute EngineMetadata service. Status: 500 Response:\nb'Could not fetch URI /computeMetadata/v1/instance/service-accounts/myproject@appspot.gserviceaccount.com/token?scopes=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fcloud-platform\\n'",<google.auth.transport.requests._Response object at 0x3e095a9f4c50>)
 File "<string>",line 3,in raise_from
   six.raise_from(new_exc,caught_exc)
 File "/env/local/lib/python3.7/site-packages/google/auth/compute_engine/credentials.py",line 117,in refresh
   self.refresh(request)
 File "/env/local/lib/python3.7/site-packages/google/auth/credentials.py",line 133,in before_request
   self._request,context.method_name,context.service_url,headers
 File "/env/local/lib/python3.7/site-packages/google/auth/transport/grpc.py",line 88,in _get_authorization_headers
   callback(self._get_authorization_headers(context),None)
 File "/env/local/lib/python3.7/site-packages/google/auth/transport/grpc.py",line 101,in __call__
   context,_AuthMetadataPluginCallback(callback_state,callback))
 File "/env/local/lib/python3.7/site-packages/grpc/_plugin_wrapping.py",line 78,in __call__
Traceback (most recent call last):

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

google.auth.exceptions.TransportError: ("Failed to retrieve http://Metadata.google.internal/computeMetadata/v1/instance/service-accounts/myproject@appspot.gserviceaccount.com/token?scopes=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fcloud-platform from the Google Compute EngineMetadata service. Status: 500 Response:\nb'Could not fetch URI /computeMetadata/v1/instance/service-accounts/myproject@appspot.gserviceaccount.com/token?scopes=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fcloud-platform\\n'",<google.auth.transport.requests._Response object at 0x3e095a9f4c50>)
   response,File "/env/local/lib/python3.7/site-packages/google/auth/compute_engine/_Metadata.py",line 187,in get
   token_json = get(request,path,params=params)
 File "/env/local/lib/python3.7/site-packages/google/auth/compute_engine/_Metadata.py",line 263,in get_service_account_token
   request,service_account=self._service_account_email,scopes=scopes
 File "/env/local/lib/python3.7/site-packages/google/auth/compute_engine/credentials.py",line 113,in refresh
Traceback (most recent call last):
AuthMetadataPluginCallback "<google.auth.transport.grpc.AuthMetadataPlugin object at 0x3e0961671dd0>" raised exception!

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)