首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何捕捉谷歌视频智能DeadlineExceeded异常?

如何捕捉谷歌视频智能DeadlineExceeded异常?
EN

Stack Overflow用户
提问于 2019-05-01 00:00:04
回答 1查看 189关注 0票数 0

我正在迭代一个很大的视频列表,并通过Google Video Intelligence运行每个视频。它适用于大多数视频,但如果视频返回异常,代码(Python 3.x)应该跳过它而不停止迭代(添加了一些代码,将导致错误的视频的名称写入CSV文件,以便稍后检查)。

我使用了try/except例程,但是即使我没有调用一个特定的异常,它也会中断迭代。

代码如下:

代码语言:javascript
运行
复制
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

这是引发的异常:

代码语言:javascript
运行
复制
  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
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-05-02 01:16:40

查看堆栈跟踪,似乎异常来自行

代码语言:javascript
运行
复制
operation = video_client.annotate_video(input_content=input_content, 
                                        features=features, 
                                        video_context=context,
                                        retry=None)

尝试将try语句上移一行。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/55924787

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档