Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3.x Azure函数在接收pdf文件时触发Http,然后使用表单识别器[python]分析表单_Python 3.x_Azure_Function - Fatal编程技术网

Python 3.x Azure函数在接收pdf文件时触发Http,然后使用表单识别器[python]分析表单

Python 3.x Azure函数在接收pdf文件时触发Http,然后使用表单识别器[python]分析表单,python-3.x,azure,function,Python 3.x,Azure,Function,因此,以下工作流程: 同事在my Azure Functions端点上发送送达回执(pdf或图像) Azure函数使用HTTP触发器接收文件 然后,该文件将由表单识别器(Microsoft的认知服务)进行分析 以Json的形式发送响应 因为我是新手,所以我有一些问题。这就是我的代码现在的样子: import logging import requests import azure.functions as func import json SUPPORTED_CONTENT_TYPES =

因此,以下工作流程:

  • 同事在my Azure Functions端点上发送送达回执(pdf或图像)
  • Azure函数使用HTTP触发器接收文件
  • 然后,该文件将由表单识别器(Microsoft的认知服务)进行分析
  • 以Json的形式发送响应 因为我是新手,所以我有一些问题。这就是我的代码现在的样子:

    import logging 
    import requests
    import azure.functions as func
    import json
    
    SUPPORTED_CONTENT_TYPES = ['application/pdf', 'image/jpeg', 'image/png']
    
    # Define Form Recognizer Dependencies
    
    apim_key = "key"
    model_id = "formrecognizer model id"
    formrecendpoint ="endpoint"
    
    def main(req: func.HttpRequest) -> func.HttpResponse:
        logging.info('Function processed a Request')
    
        # recieve the file
        file = req.files.get('file')
    
        body = None
    
        # Analyze Forms Endpoint  
        endpoint = '......cognitive.microsoft.com/formrecognizer/v2.0-preview/cutom/models/modelID/analyze'
    
        # Analyze Form
        response = requests.post(endpoint, data = file, headers = {"Content-Type": '<file type>',"Ocp-Apim-Subscription-Key": apim_key})
        body = response.content
    
        #Return Response
        return func.HttpResponse(body,headers={'Content-Type':'application/json'})
    

    但是在函数本身中,我得到了
    状态:200

    这是实际的URL,还是您有一个
    modelID
    ?错误表示“分析请求无效或缺少必需的参数”,因此请查看。函数返回
    状态200
    的原因是您总是返回
    func.HttpResponse
    。URL不应该是问题所在。我仔细检查了几次。我有一个自定义模型ID。我很确定我没有正确地传递正文和参数。这是实际的URL,还是您有一个
    modelID
    ?错误表示“分析请求无效或缺少必需的参数”,因此请查看。函数返回
    状态200
    的原因是您总是返回
    func.HttpResponse
    。URL不应该是问题所在。我仔细检查了几次。我有一个自定义模型ID。我很确定我没有正确地通过身体和参数。
    {
        "error": {
            "code": "1002",
            "message": "Analyze request is either invalid or missing required parameters. Refer to the API reference and retry your request."
        }
    }