0

How can I obtain the operation object using the operation name in python client.

 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

Now I need to use this name to get the operation and poll for its status

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

But I get error: Traceback (most recent call last): File "", line 1, in File "env/local/lib/python2.7/site-packages/googleapiclient/discovery.py", line 742, in method (name, pvalue, regex)) TypeError: Parameter "name" value "projects/my-project/locations/us-east1/operations/123" does not match the pattern "^operations/.*$"

So I tried with:

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

But it gives me another error:

Traceback (most recent call last): File "", line 1, in File "env/local/lib/python2.7/site-packages/googleapiclient/_helpers.py", line 130, in positional_wrapper return wrapped(*args, **kwargs) File "env/local/lib/python2.7/site-packages/googleapiclient/http.py", line 842, in execute raise HttpError(resp, content, uri=self.uri) HttpError: https://cloudresourcemanager.googleapis.com/v1/operations/123?alt=json returned "field [name] has issue [invalid operation name]">

What is the correct way to obtain the operation object from name in python client ? Thanks.

user4848830
  • 779
  • 12
  • 22

1 Answers1

0

I was able to obtain the operation by name as follows:

from google.api_core import operations_v1
api = operations_v1.OperationsClient(video_client.transport.channel)
operation = api.get_operation(operation_name)
user4848830
  • 779
  • 12
  • 22