python - 将 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
解决方案
Google Vision Intelligence 就像其他 google 服务一样,使用 gRPC 与服务后端进行通信。不幸的是,VCR 还不支持 gRPC。
测试期间 VCR 记录的唯一内容是 OAuth 令牌(检查了 VCR 生成的磁带文件)。当它过期时,它将导致Unauthenticated
错误
参考:
关于 gRPC 支持的功能请求 https://github.com/kevin1024/vcrpy/issues/560
用于 gRPC (Ruby) 的 VCR https://github.com/btoews/gcr
推荐阅读
- ruby-on-rails - 在rails中结合两种方法
- sql-server - “字符串或二进制数据将被截断”的解决方案
- java - 为什么 synchronized(ThreadB) ,ThreadB destroy 可以自动通知?
- docker - 1 out 5 fluentd 处于 ImagePullBackOff 状态
- php - 为 SAAS 客户组织 DNS 服务
- node.js - 我使用 create-react-app 创建了一个应用程序,但我无法通过“npm start”启动它
- c# - 枚举名称生成 nswag 和 swashbuckle
- prolog - 为什么不脱糖的“。” 列表的仿函数语法与 [] 的工作方式相同吗?
- javascript - 使用 addEventListener 时无法使用 GamepadEvent
- sql - 如何使用sql从两个表中获取数据