Google Cloud vision API:"请求的身份验证范围不足."

Ral*_*ova 6 python google-cloud-platform google-cloud-vision

嗨,我正在尝试使用谷歌的云视觉API,特别是这个例子:https://cloud.google.com/vision/docs/label-tutorial#label_tutorial_1

我按照本教程:https://cloud.google.com/vision/docs/getting-started#set_up_a_service_account来设置服务帐户,但是当我运行我的代码时,我得到:

googleapiclient.errors.HttpError: <HttpError 403 when requesting https://vision.googleapis.com/$discovery/rest?version=v1 returned "Request had insufficient authentication scopes.">
Run Code Online (Sandbox Code Playgroud)

有人可以帮忙吗?我无法弄清楚发生了什么,我的代码是1:1的教程.

ago*_*ken 6

您需要~/.credentials/sheets.googleapis.com-python-quickstart.json从计算机上清理.然后将您的范围定义为https://www.googleapis.com/auth/drive.再次运行您的代码,它应该要求您重新授权.然后运行你的代码.


小智 3

我遇到了同样的错误。我做了以下事情:

sudo apt-get update & apt-get upgrade

pip install --upgrade google-api-python-client
Run Code Online (Sandbox Code Playgroud)

然后通过...初始化 gcloud sdk

gcloud init 
Run Code Online (Sandbox Code Playgroud)

瞧,它开始工作了!

您还可以尝试从 API 管理器重新生成凭据