python - azure python 函数在 vscode 本地运行,但不在 azure PAYG functon 应用程序中运行。httpRequest.headers["referer"] 有问题吗?
问题描述
我从 Azure 日志中收到以下错误消息:
Result: Failure Exception: KeyError: 'referer' Stack: File "/azure-functions-
host/workers/python/3.7/LINUX/X64/azure_functions_worker/dispatcher.py", line 372, in
_handle__invocation_request self.__run_sync_func, invocation_id, fi.func, args) File
"/usr/local/lib/python3.7/concurrent/futures/thread.py", line 57, in run result = self.fn(*self.args,
**self.kwargs) File "/azure-functions
host/workers/python/3.7/LINUX/X64/azure_functions_worker/dispatcher.py", line 548, in __run_sync_func
return func(**params) File "/home/site/wwwroot/createCheckoutSession/__init__.py", line 18, in main
logging.info(req.headers["referer"]) File "/azure-functions-
host/workers/python/3.7/LINUX/X64/azure/functions/_http.py", line 27, in __getitem__ return
self.__http_headers__[key.lower()]
我认为有问题的代码是:
logging.info(req.headers["referer"])
logging.info(os.environ["stripe_api_key"])
BASEURL = req.headers["referer"] + "#"
Azure 似乎正在努力从 req.headers 中提取引用。它适用于 VScode。在 Stripe 支付请求后,我使用引荐来源网址构建重定向 URL。这种重定向在 DEV、TEST 和 PROD 中明显不同。任何想法我做错了什么。
解决方案
根据你的描述,我用下面的代码做了一些测试:
import logging
import azure.functions as func
def main(req: func.HttpRequest) -> func.HttpResponse:
logging.info(req.headers["referer"])
BASEURL = req.headers["referer"] + "#"
return func.HttpResponse(
BASEURL,
status_code=200
)
但无论是在本地云还是 Azure 云上,它都可以例外地工作:
那么,您能否请检查一下,如果您还有其他问题,请告诉我?
推荐阅读
- c - 分数数组
- docker - 将文件从主机替换为具有已安装卷的容器
- kubernetes - 如何编辑 Kubernetes 集群角色定义
- javascript - 如何将获取数据的结果分配给变量?ReactJS
- google-cloud-sql - Google Cloud SQL 实例卡在“实例正在更新”中
- c# - LINQ to Entities 无法识别该方法(布尔值)
- sql-server - 以月和日计算两个日期之间的时间段
- tfs - 需要一次将用户添加到所有团队项目
- reporting-services - SSRS 表达式 IIF 在 if true 部分带有聚合函数
- python-3.x - python:3.8-alpine3.11 中的 Scipy 错误 - 找不到 lapack/blas 资源