首页 > 解决方案 > AttributeError:“str”对象没有属性“annotate_video”

问题描述

在 JupyterLab 上使用以下代码来运行 Google Video Intelligence 包:

from google.cloud import videointelligence
import os

client = videointelligence.VideoIntelligenceServiceClient('VidIntelligence.JSON')
job = client.annotate_video(
    input_uri='gs://vidintelligencebucket/The Simpsons - Monopoly Night.mp4',
    features=['LABEL_DETECTION', 'SHOT_CHANGE_DETECTION'],
)
result = job.result()

当我运行它时,会出现以下错误:

AttributeError: 'str' object has no attribute 'annotate_video'

有什么建议么?

标签: pythonjupyter-labgoogle-visionvideo-intelligence-api

解决方案


发生这种情况是因为ex4指出变量client是类型str并且只包含错误消息。

发生错误是因为您尝试以不正确的方式进行身份验证。传递给credentials客户端参数的参数不能是类型str,而应该是描述中所述的Credentials对象。client

您可以查看此概述以了解验证客户端的所有有效方法。

由于您有一个json带有凭据的文件,您只需要使用名为的环境变量指向它GOOGLE_APPLICATION_CREDENTIALS

$ export GOOGLE_APPLICATION_CREDENTIALS="/path/to/VidIntelligence.json"

然后您将能够在不传递任何参数的情况下初始化您的客户端:

client = videointelligence.VideoIntelligenceServiceClient()

希望这会有所帮助!


推荐阅读