AttributeError:'str'对象没有属性'annotate_video'

问题描述 投票:0回答:1

在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'

有什么建议吗?

python jupyter-lab google-vision video-intelligence-api
1个回答
0
投票

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

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

您可以在overview上检查所有用于验证客户端的有效方法。

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

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

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

client = videointelligence.VideoIntelligenceServiceClient()

希望有帮助!

© www.soinside.com 2019 - 2024. All rights reserved.