0

如何在 python 客户端中使用操作名称获取操作对象。

 video_client = videointelligence.VideoIntelligenceServiceClient()
    features = [videointelligence.enums.Feature.TEXT_DETECTION]
    operation = video_client.annotate_video(
        input_uri=input_uri,
        features=features
    )
   # operation.operation.name has the operation name

现在我需要使用这个名称来获取操作并轮询它的状态

 service = discovery.build('cloudresourcemanager', 'v1')
 request = service.operations().get(name=operation.operation.name)

但我得到错误: Traceback(最近一次调用最后一次):文件“”,第 1 行,在文件“env/local/lib/python2.7/site-packages/googleapiclient/discovery.py”中,第 742 行,在方法中( name, pvalue, regex)) TypeError: 参数“name”值“projects/my-project/locations/us-east1/operations/123”与模式“^operations/.*$”不匹配

所以我尝试了:

service = discovery.build('cloudresourcemanager', 'v1')
request = service.operations().get(name='operations/123')
response = request.execute()

但它给了我另一个错误:

回溯(最后一次调用):文件“”,第 1 行,在文件“env/local/lib/python2.7/site-packages/googleapiclient/_helpers.py”中,第 130 行,在 positional_wrapper 中返回包装(*args, **kwargs) 文件“env/local/lib/python2.7/site-packages/googleapiclient/http.py”,第 842 行,在执行 raise HttpError(resp, content, uri=self.uri) HttpError: https:// /cloudresourcemanager.googleapis.com/v1/operations/123?alt=json 返回“字段 [名称] 有问题 [操作名称无效]”>

从 python 客户端中的名称获取操作对象的正确方法是什么?谢谢。

4

1 回答 1

0

我能够按名称获取操作,如下所示:

from google.api_core import operations_v1
api = operations_v1.OperationsClient(video_client.transport.channel)
operation = api.get_operation(operation_name)
于 2020-03-03T17:24:51.877 回答