python - 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'
有什么建议么?
解决方案
发生这种情况是因为ex4指出变量client
是类型str
并且只包含错误消息。
发生错误是因为您尝试以不正确的方式进行身份验证。传递给credentials
客户端参数的参数不能是类型str
,而应该是描述中所述的Credentials对象。client
您可以查看此概述以了解验证客户端的所有有效方法。
由于您有一个json
带有凭据的文件,您只需要使用名为的环境变量指向它GOOGLE_APPLICATION_CREDENTIALS
:
$ export GOOGLE_APPLICATION_CREDENTIALS="/path/to/VidIntelligence.json"
然后您将能够在不传递任何参数的情况下初始化您的客户端:
client = videointelligence.VideoIntelligenceServiceClient()
希望这会有所帮助!
推荐阅读
- google-apps-script - 将 Google 表格作为 HTML 表格发布到 Google 站点
- javascript - 寻找 fetch js/css 解决方案
- reactjs - React Firebase 退出
- php - Restful PHP,方法 POST 获取参数
- apache-spark-sql - 如何在 spark sql 中使用过滤器获取费率:Struct to get BGN,BRL in range between (2019-01-02 , 2019-01-04)
- angular - 如何在指令中使用 ngx translate
- c# - 如何使用 C# 的管理员权限启动 PowerShell?
- javascript - 在 Gatsby 中查询子节点字段
- python - 如何在我的 tkinter 窗口上显示我的控制台日志?
- typescript - 如何从构造函数继承类变量类型?