属性错误: 'str'对象没有属性'annotate_video'



在JupyterLab上使用以下代码来运行谷歌视频智能包:

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'

有什么建议吗?

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

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

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

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

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

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

client = videointelligence.VideoIntelligenceServiceClient()

希望这能有所帮助!

最新更新