
[英]Azure Data Factory copy data from json string nested in a json
[英]Why am I not be able to post json array from Azure Function activity at Azure Data Factory?
我在 Azure 数据工厂上创建了 Azure Function 活动。 Azure Function 活动调用 function 的 Azure Function 应用程序(Python,应用程序服务计划)。
Python 代码如下所示:
# ...
def get_request(self, req: func.HttpRequest):
request_body_json = req.get_json()
# ...
当我将 json 数组作为 Azure Function 活动的请求正文(如[{"key1": "value1"}, {"key2": "value2"}]
)传递时,会发生ValueError
。
但是,当我将相同的 json 数组传递给 Web 活动时,不会发生错误。 Web 活动调用与 Azure Function 活动相同的 Python 代码。
为什么我无法从 Azure 数据工厂的 Azure Function 活动发布 json 数组?
我已经在我的环境中进行了复制,以下过程对我有用:首先,我已经在 web 活动中进行了复制,并且我已经成功地尝试了您的代码,如下所示:
当我尝试使用 Function 活动时出现错误。
Function adf 中的活动不作为正文传递 Json 它作为文本传递。 所以,我们需要为此使用一个数组变量。
所以,我设置了一个变量如下:
设置变量后,我创建了一个 azure function 活动,如下所示:
{
"rithwik":@{variables('emo')}
}
然后在function代码中:
import logging
import azure.functions as func
def main(req: func.HttpRequest) -> func.HttpResponse:
logging.info('Python HTTP trigger function processed a request.')
request_body_json = req.get_json()
return func.HttpResponse(f"Received the message: {request_body_json['rithwik']}", status_code=200)
request_body_json['rithwik']
因为它将打印值。
Output:
参考:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.