首页 > 解决方案 > 将 python vcr 与 Google Video Intelligence 一起使用 - 请求出错

问题描述

当我使用 python vcr 运行测试时,我遇到了一个奇怪的谷歌视频智能 api 请求错误。我想知道是否有其他人看到过这个错误,如果有,我们为什么会有这个错误以及如何解决它?

我使用 VCR 来模拟对视频智能 api 的请求。

我使用 pytest 来运行我的测试。

如果我删除 VCR 并重新运行它运行良好,并且如果我在创建 vcr 后再次运行它,它也运行良好。但是过了一会儿,(目前不确定这是几小时还是几天,我会在运行 vcr 时收到以下错误)。

错误如下: -

"Request had invalid authentication credentials. Expected OAuth 2 access token, login cookie or other valid authentication credential. 

这是录像机错误


    E   google.api_core.exceptions.Unauthenticated: 401 Request had invalid authentication credentials. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project.
    <string>:3: Unauthenticated
    Assertion failed

标签: pythongoogle-appsvcrvideo-intelligence-api

解决方案


Google Vision Intelligence 就像其他 google 服务一样,使用 gRPC 与服务后端进行通信。不幸的是,VCR 还不支持 gRPC。

测试期间 VCR 记录的唯一内容是 OAuth 令牌(检查了 VCR 生成的磁带文件)。当它过期时,它将导致Unauthenticated错误

参考:


推荐阅读