Python GCP功能可以';不要互相打电话
我无法让GCP函数通过身份验证向其他函数发送请求。我确实有运行时服务帐户的服务密钥。这是我使用的代码。我拿到401Python GCP功能可以';不要互相打电话,python,http,google-cloud-platform,Python,Http,Google Cloud Platform,我无法让GCP函数通过身份验证向其他函数发送请求。我确实有运行时服务帐户的服务密钥。这是我使用的代码。我拿到401 service_account_key = json.loads(creds) creds = service_account.IDTokenCredentials.from_service_account_info( service_account_key, target_audience=url ) request = google.auth.trans
service_account_key = json.loads(creds)
creds = service_account.IDTokenCredentials.from_service_account_info(
service_account_key, target_audience=url
)
request = google.auth.transport.requests.Request()
creds.refresh(request=request)
token = creds.token
r = authed_session.post(
url=url,
json=data,
headers={
'content-type': 'application/json',
'authorization': f'bearer {token}'
}
)
print(r.text)
首先,在云计算功能中,您不应该(不得)使用服务帐户密钥文件。实际上,您可以自定义,然后从 一段时间。链接指向云运行服务,但底层基础设施相同,云运行文档更好。您需要一个id_令牌才能调用您的云函数
此外,要将请求者服务帐户授权为cloudfunctions.invoker。如果您在云函数中,当您可以使用特定的服务帐户()启动云函数时,为什么要使用服务帐户密钥?对于您的授权问题,请确保调用者在目标CF上具有role
roles/cloudfunctions.invoker
。谢谢!您的回答帮助我正确地获得了它(没有服务帐户密钥),并找到了真正的问题——我的请求被发送到http而不是https。