简体   繁体   English

如何捕获 Google Video Intelligence DeadlineExceeded 异常?

[英]How to catch Google Video Intelligence DeadlineExceeded exception?

I'm iterating a big list of videos and running each one through Google Video Intelligence.我正在迭代一大堆视频并通过 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).它适用于大多数视频,但如果视频返回异常,代码(Python 3.x)应该跳过它而不停止迭代(添加一些代码以将产生错误的视频的名称写入 CSV 文件以稍后检查)。

I used the try/except routine, but even if I do not call a specific exception, which should catch any, it breaks the iteration.我使用了 try/except 例程,但即使我没有调用应该捕获任何异常的特定异常,它也会中断迭代。

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

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.尝试将您的try语句向上移动。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用 Google Cloud DocumentAI V1 批处理文档时出现异常 - StatusCode="DeadlineExceeded" - Exception while batch processing document with Google Cloud DocumentAI V1 - StatusCode="DeadlineExceeded" 谷歌云 Pus/Sub:: google.api_core.exceptions.DeadlineExceeded:超过 504 最后期限 - Google Cloud Pus/Sub :: google.api_core.exceptions.DeadlineExceeded: 504 Deadline Exceeded 谷歌云 Function 捕获 BQ 存储过程异常 - Google Cloud Function to catch BQ Stored proc exception 如何捕获无服务器的异常 SQL 服务器冷启动 - How to catch exception for a serverless SQL Server cold boot 如何将本地视频文件上传到 Google Cloud - How to upload local video file to Google Cloud 从 Airflow 抓取时捕获 Scrapy 异常 - Catch Scrapy exception when crawling from Airflow 自定义域/捕获 Google App Engine 上的所有主机名 - Custom domains / catch all hostnames on Google App Engine 如何正确处理 try-catch 的错误 - How to properly handle an error with try-catch 取消 Google 登录会导致 Flutter 出现异常 - Canceling Google Sign In cause an exception in Flutter 我哪里错了? 尝试创建 UserWithEmailAndPassword 时代码从不捕获异常 - Where am I wrong? The code never catch an exception while trying to createUserWithEmailAndPassword
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM