如何从Azure Function应用程序中的Data Factory任务接收/访问POST请求和“用户属性”的标头

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

我还是Azure的新手,所以如果这是一个新手问题,请耐心等待。

我在Azure Data Factory中创建了一个任务,该任务将调用Http触发的Python函数(消耗计划)。该任务的设置和用户属性如下所示:

enter image description here

和这里

enter image description here

功能本身如下所示:

enter image description here

Q1:我想知道如何在Python函数中读取/访问POST请求的标题(上面屏幕截图中的'run.py')。现在,我只能使用os.environ['req']访问HTTP请求的主体。

Q2:我还想知道是否可以访问'run.py'中的'User Properties',假设我在Data Factory中运行任务(第一个和第二个屏幕截图)。如果是这样,我该怎么做。

我在网上找到的现有资源(例如12)还没告诉我。任何建议/提示将不胜感激。先感谢您!

azure azure-functions azure-data-factory azure-data-factory-2
1个回答
1
投票

我终于弄清楚了,并且正在分享我在下面找到的东西,这样它就可以帮助每个人在那里和我一样的想法。

这是我在Python Function App中编写的用于访问正文和请求标头的代码。

import os
import json

# This is how I'm currently reading the **body of the POST request**
postreqdata = json.loads(open(os.environ['req']).read())

# This is how we should read **a header of the POST request**;
# here 'excelSourcePath' is one of the header names.
postreqdata['header1'] = os.environ['REQ_HEADERS_EXCELSOURCEPATH']

# 'User Properties' is just for monitoring purpose
# https://social.msdn.microsoft.com/Forums/en-US/8692cd00-307b-4204-a547-bed2030cb762/adfv2-user-property-setting?forum=AzureDataFactory

response = open(os.environ['res'], 'w')
response.write(json.dumps({'This is what I see from POST request now':postreqdata}))
response.close()

希望这是有帮助的。

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