【发布时间】:2019-03-03 12:19:17
【问题描述】:
我在尝试从 Web 执行 Cloud Function 端点时收到以下错误:
<!DOCTYPE html>
<html lang=en>
<meta charset=utf-8>
<meta name=viewport content="initial-scale=1, minimum-scale=1, width=device-width">
<title>Error 403 (Forbidden)!!1</title>
<style>
*{margin:0;padding:0}html,code{font:15px/22px arial,sans-serif}html{background:#fff;color:#222;padding:15px}body{margin:7% auto 0;max-width:390px;min-height:180px;padding:30px 0 15px}* > body{background:url(//www.google.com/images/errors/robot.png) 100% 5pxno-repeat;padding-right:205px}p{margin:11px 0 22px;overflow:hidden}ins{color:#777;text-decoration:none}a img{border:0}@media screen and (max-width:772px){body{background:none;margin-top:0;max-width:none;padding-right:0}}#logo{background:url(//www.google.com/images/branding/googlelogo/1x/googlelogo_color_150x54dp.png) no-repeat;margin-left:-5px}@media only screen and (min-resolution:192dpi){#logo{background:url(//www.google.com/images/branding/googlelogo/2x/googlelogo_color_150x54dp.png) no-repeat 0% 0%/100% 100%;-moz-border-image:url(//www.google.com/images/branding/googlelogo/2x/googlelogo_color_150x54dp.png) 0}}@media only screen and (-webkit-min-device-pixel-ratio:2){#logo{background:url(//www.google.com/images/branding/googlelogo/2x/googlelogo_color_150x54dp.png) no-repeat;-webkit-background-size:100% 100%}}#logo{display:inline-block;height:54px;width:150px}
</style>
<a href=//www.google.com/><span id=logo aria-label=Google></span></a>
<p><b>403.</b> <ins>That’s an error.</ins>
<p>Access is forbidden. <ins>That’s all we know.</ins>
我遵循了这个教程:https://github.com/GoogleCloudPlatform/python-docs-samples/blob/master/functions/helloworld/main.py
调用此处所述的函数时:https://cloud.google.com/functions/docs/writing/http,我收到 403 错误。我已登录 gcloud 项目并使用正确的用户。
部署命令:
gcloud beta functions deploy hello_get --runtime python37 --trigger-http
来自此文档:https://cloud.google.com/functions/docs/concepts/python-runtime
使用以下命令调用它:
curl -X POST https://<REGION-PROJECT_ID>.cloudfunctions.net/hello_get
来自此文档:https://cloud.google.com/functions/docs/writing/http
这很奇怪,因为这发生在大约 3 周前。旧函数停止工作并返回 403 响应。我在 UI 中部署了示例函数,它仅在从 UI 部署时有效,但在通过 http 请求访问端点时失败并出现 403。
另外,使用命令时函数成功执行:gcloud functions call hello_get
过去几周 GCF 身份验证是否发生了变化?
更新 我能够确定问题所在。我参与的项目和用户在一个 beta 身份验证程序中。切换到不在程序中的用户和项目后,我能够访问端点。
感谢您的帮助。
【问题讨论】:
-
问题不是由于身份验证。默认情况下,Cloud Functions 未经过身份验证,并且可供任何调用者使用。您的问题在其他地方,但从您的摘要中我不清楚这可能在哪里。相同的函数(重复调用)是否继续返回 403?当你使用 UI 进行部署时,是在同一个项目中吗?这特别令人好奇,因为它验证项目已启用,计费已启用并且功能已部署,因此很奇怪通过
curl调用将不起作用。你检查过日志吗?次要观点:POST有效,但这可能是GET。
标签: google-cloud-platform google-cloud-functions