首页 > 解决方案 > 为什么在 Vertex AI 示例中 Cloud Function 无法访问元数据服务器?

问题描述

我遵循了这个 Vertex AI 教程。但是,在最后一步,当云函数调用预测端点时,它会失败。

这意味着它甚至无法访问元数据服务器。即,不是权限失败(尽管我确实检查了myproject@appspot.gserviceaccount.com服务帐户确实具有指定的项目编辑角色)。严格来说,这也是 Functions 和 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!

标签: google-cloud-functionsgoogle-iamgoogle-ai-platformgoogle-cloud-ai-platform-pipelines

解决方案


推荐阅读