Reputation: 3
I'm iterating a big list of videos and running each one through Google Video Intelligence. It works fine for most videos, but if a video returns an exception, the code (Python 3.x) should skip it without stopping the iteration (added some code to write the name of the video which originated the error to a CSV file to check later).
I used the try/except routine, but even if I do not call a specific exception, which should catch any, it breaks the iteration.
This is the code:
from google.cloud import videointelligence
from google.api_core.exceptions import *
(...)
operation = video_client.annotate_video(input_content=input_content,
features=features,
video_context=context,
retry=None)
try:
result = operation.result(timeout=600)
except:
result = False
pass
This is the exception raised:
File "/home/bernardo/.local/lib/python3.6/site-packages/google/api_core/grpc_helpers.py", line 57, in error_remapped_callable
return callable_(*args, **kwargs)
File "/home/bernardo/.local/lib/python3.6/site-packages/grpc/_channel.py", line 549, in __call__
return _end_unary_response_blocking(state, call, False, None)
File "/home/bernardo/.local/lib/python3.6/site-packages/grpc/_channel.py", line 466, in _end_unary_response_blocking
raise _Rendezvous(state, None, None, deadline)
grpc._channel._Rendezvous: <_Rendezvous of RPC that terminated with:
status = StatusCode.DEADLINE_EXCEEDED
details = "Deadline Exceeded"
debug_error_string = "{"created":"@1556638076.747183038","description":"Error received from peer","file":"src/core/lib/surface/call.cc","file_line":1039,"grpc_message":"Deadline Exceeded","grpc_status":4}"
>
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "annotate_videos.py", line 153, in <module>
main()
File "annotate_videos.py", line 149, in main
process_videos(videos)
File "annotate_videos.py", line 127, in process_videos
result = annotate_videos_alternative(fallback_url)
File "annotate_videos.py", line 59, in annotate_videos_alternative
retry=None)
File "/home/bernardo/.local/lib/python3.6/site-packages/google/cloud/videointelligence_v1/gapic/video_intelligence_service_client.py", line 282, in annotate_video
request, retry=retry, timeout=timeout, metadata=metadata
File "/home/bernardo/.local/lib/python3.6/site-packages/google/api_core/gapic_v1/method.py", line 143, in __call__
return wrapped_func(*args, **kwargs)
File "/home/bernardo/.local/lib/python3.6/site-packages/google/api_core/timeout.py", line 214, in func_with_timeout
return func(*args, **kwargs)
File "/home/bernardo/.local/lib/python3.6/site-packages/google/api_core/grpc_helpers.py", line 59, in error_remapped_callable
six.raise_from(exceptions.from_grpc_error(exc), exc)
File "<string>", line 3, in raise_from
google.api_core.exceptions.DeadlineExceeded: 504 Deadline Exceeded
Upvotes: 0
Views: 268
Reputation: 1620
Looking at the stack trace, it seems the exception is coming from the line
operation = video_client.annotate_video(input_content=input_content,
features=features,
video_context=context,
retry=None)
Try moving your try
statement a line up.
Upvotes: 1