【发布时间】:2020-08-17 19:19:26
【问题描述】:
我正在尝试使用以下代码从 Python 中向 Google Cloud 函数发出授权请求:
import google.auth
from google.auth.transport.urllib3 import AuthorizedHttp
credentials, project = google.auth.default()
authed_http = AuthorizedHttp(credentials)
url = "MY_CLOUD_FUNCTON_URL"
response = authed_http.request('POST', url)
但我收到以下错误:
google.auth.exceptions.RefreshError: ('invalid_scope: Invalid OAuth scope or ID token audience provided.', '{"error":"invalid_scope","error_description":"Invalid OAuth scope or ID token audience provided."}')
这让我觉得我的凭据设置不正确,但如果我使用以下命令从命令行运行它,调用就可以工作:
gcloud functions call MY_CLOUD_FUNCTION --data '{"name":"example"}'
有人知道我为什么会收到这个错误吗?任何帮助将不胜感激!
【问题讨论】:
-
你在哪里运行调用函数的 Python 脚本?
标签: python google-cloud-platform python-requests google-cloud-functions