gpt4 book ai didi

python - google.gax.errors.RetryError StatusCode.DEADLINE_EXCEEDED

转载 作者:太空宇宙 更新时间:2023-11-03 15:06:52 24 4
gpt4 key购买 nike

来自这个github: https://github.com/GoogleCloudPlatform/python-docs-samples

我正在尝试测试视频智能 API 并进行标签分析。

import argparse
import sys
import time
import io
import base64

from google.cloud.gapic.videointelligence.v1beta1 import enums
from google.cloud.gapic.videointelligence.v1beta1 import (
video_intelligence_service_client)
# [END imports]


#python labels.py /Users/rockbaek/tildawatch-contents/EpicSkillShot/M7-_VukSueY/SKT\ vs\ KT\ Game\ 3\ _\ Grand\ Finals\ S7\ LCK\ Spring\ 2017\ _\ KT\ Rolster\ vs\ SK\ Telecom\ T1\ G3\ 1080p-M7-_VukSueY.mp4

def analyze_labels_file(path):
""" Detects labels given a file path. """
video_client = (video_intelligence_service_client.
VideoIntelligenceServiceClient())
features = [enums.Feature.LABEL_DETECTION]

with io.open(path, "rb") as movie:
content_base64 = base64.b64encode(movie.read())

operation = video_client.annotate_video(
'', features, input_content=content_base64)
print('\nProcessing video for label annotations:')

while not operation.done():
sys.stdout.write('.')
sys.stdout.flush()
time.sleep(15)

print('\nFinished processing.')

# first result is retrieved because a single video was processed
results = operation.result().annotation_results[0]

for i, label in enumerate(results.label_annotations):
print('Label description: {}'.format(label.description))
print('Locations:')

for l, location in enumerate(label.locations):
positions = 'Entire video'
if (location.segment.start_time_offset != -1 or
location.segment.end_time_offset != -1):
positions = '{} to {}'.format(
location.segment.start_time_offset / 1000000.0,
location.segment.end_time_offset / 1000000.0)
print('\t{}: {}'.format(l, positions))

print('\n')

if __name__ == '__main__':
# [START running_app]
parser = argparse.ArgumentParser(
description=__doc__,
formatter_class=argparse.RawDescriptionHelpFormatter)
parser.add_argument('path', help='GCS file path for label detection.')
args = parser.parse_args()

analyze_labels_file(args.path)
# [END running_app]
# [END full_tutorial]

然后我从终端运行它python labels.py MP4_FILE_PATH

一段时间后,它失败并显示以下错误代码:

Traceback (most recent call last):
File "labels.py", line 123, in <module>
analyze_labels_file(args.path)
File "labels.py", line 52, in analyze_labels_file
'', features, input_content=content_base64)
File "/Library/Python/2.7/site-packages/google/cloud/gapic/videointelligence/v1beta1/video_intelligence_service_client.py", line 237, in annotate_video
self._annotate_video(request, options), self.operations_client,
File "/Library/Python/2.7/site-packages/google/gax/api_callable.py", line 428, in inner
return api_caller(api_call, this_settings, request)
File "/Library/Python/2.7/site-packages/google/gax/api_callable.py", line 416, in base_caller
return api_call(*args)
File "/Library/Python/2.7/site-packages/google/gax/api_callable.py", line 376, in inner
return a_func(*args, **kwargs)
File "/Library/Python/2.7/site-packages/google/gax/retry.py", line 144, in inner
raise exc
google.gax.errors.RetryError: GaxError(Retry total timeout exceeded with exception, caused by <_Rendezvous of RPC that terminated with (StatusCode.DEADLINE_EXCEEDED, Deadline Exceeded)>)

请帮忙解释为什么它不起作用! :(

最佳答案

对于 future 的访问者,我在使用 Cloud Speech API 时遇到了同样的错误。

我刚刚在调用 operation.result 时增加了timeout 值。这解决了它。虽然这个片段不在OP的代码中,但它应该在提到的Google示例代码OP中。

operation.result(timeout=90)   # increase this numeric value

关于python - google.gax.errors.RetryError StatusCode.DEADLINE_EXCEEDED,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44577311/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com