在谷歌云功能中未接收客户端标头

问题描述 投票:0回答:1

我正在使用 Google 云函数,并且已经部署并一直在使用 Flask 应用程序的第二代函数。我正在使用 Hasura 操作来触发这些功能。最近,在我更新和部署代码后,它开始将我从 Hasura 操作传递的标头显示为

None
。除了我更新的云函数之外的所有云函数都在获取标头。有人遇到过收不到发送的标头的问题吗?

为了确认这一点,我又更新了一项云功能,它也开始以同样的方式运行。我已经记录了我在云功能中收到的所有标头,并确认没有任何拼写错误或此类错误。

我使用的是python 3.11版本和第二代云函数。

import json

@functions_framework.http
def main(request):
    try:
        action_secret = request.headers.get("action_secret")

        if action_secret != os.environ.get("action_secret"):
            logging.error("Unauthorized access")
            return json.dumps(
                {"err_msg": "You are not authorized to perform this action"}
            )
    except Exception as e:
        print(e) # I get the error log as action_secret is not in request.headers

更新:

  • 我已经通过多种方式进行了测试,发现这是 Hasura 未发送标头的问题。
python flask google-cloud-functions hasura request-headers
1个回答
0
投票

发现错误是由于 hasura 操作客户端标头中的下划线引起的。我使用的变量是“action_secret”,当我将其修改为“actionsecret”时,云功能开始正常工作。

© www.soinside.com 2019 - 2024. All rights reserved.