[英]Google Cloud Auto ML Vision Permission Denied
我在 Google Cloud Platform Auto ML Vision API 遇到了一個奇怪的情況。 當我執行 API 請求時,它總是拋出一個錯誤,說 PERMISSION DENIED,請參閱下面的示例錯誤響應:
{
"error": {
"code": 403,
"message": "The caller does not have permission",
"status": "PERMISSION_DENIED"
}
}
這是我到目前為止所做的:
集成預測 rest api 並使用以下代碼生成不記名令牌:
var credentials: GoogleCredentials = GoogleCredentials.fromStream(context.assets.open("service_account_key.json")).createScoped(Lists.newArrayList("https://www.googleapis.com/auth/cloud-platform")) credentials.refreshIfExpired() val accesstoken = credentials.accessToken
您能否將這些范圍添加到您的憑據中:
https://www.googleapis.com/auth/cloud-platform
#(View and manage your data across Google Cloud Platform services)
https://www.googleapis.com/auth/cloud-vision
#(Apply machine learning models)
您也可以運行此命令來測試您的服務帳戶是否具有 wright 權限。 如果這有效,那么您的代碼有問題。
gcloud auth activate-service-account [ACCOUNT] --key-file=KEY_FILE
curl -X GET -H "Authorization: Bearer $(gcloud auth application-default print-access-token)" -H "Content-Type: application/json" https://automl.googleapis.com/v1beta1/projects/${PROJECT_ID}/locations/us-central1/models
在“IAM & Admin”中創建一個新的服務帳戶並下載一個新的 JSON 密鑰文件(然后更新您的代碼以反映新文件名)。
我只花了 12 個小時來解決這個問題,並嘗試了所有可能的解決方案。 最后,唯一解決此問題的是創建一個新的服務帳戶。
我同時使用 Windows 和基於 Debian 的 Linux,這個問題不是特定於環境的。 我還在 Python 和 PHP 中使用了我的 JSON 密鑰。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.