You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Azure Form Recognizer Python SDK调用成功但键值对返回为空求助

Azure Form Recognizer自定义模型SDK调用异常排查

我用Form Recognizer Studio创建了自定义模型,上周Python SDK调用正常,这周突然出问题——API调用都成功,但返回的键值对几乎为空。在Form Recognizer Studio测试相同文档时,模型能正确捕获所有键值对,但SDK的poller.result()结果里只有一个字段有值还不正确。

调用响应日志

2023-03-17 19:08:17,558 |  INFO Request URL: 'https://pedimento.cognitiveservices.azure.com/formrecognizer/documentModels/PedimentoModelCopy:analyze?pages=1&locale=en&stringIndexType=unicodeCodePoint&api-version=2022-08-31'
Request method: 'POST'
Request headers:
    'Content-Type': 'application/octet-stream'
    'Accept': 'application/json'
    'x-ms-client-request-id': '0502a4f2-c4b4-11ed-b9d7-5414f3f87608'
    'User-Agent': 'azsdk-python-ai-formrecognizer/3.2.0 Python/3.9.1 (Windows-10-10.0.19041-SP0)'
    'Ocp-Apim-Subscription-Key': 'REDACTED'
A body is sent with the request
2023-03-17 19:08:19,520 |  INFO Response status: **202**
Response headers:
    'Content-Length': '0'
    'Operation-Location': 'https://pedimento.cognitiveservices.azure.com/formrecognizer/documentModels/PedimentoModelCopy/analyzeResults/590eb38b-87b0-44d5-bb5e-f719e94e52cb?api-version=2022-08-31'
    'x-envoy-upstream-service-time': '378'
    'apim-request-id': '590eb38b-87b0-44d5-bb5e-f719e94e52cb'
    'Strict-Transport-Security': 'max-age=31536000; includeSubDomains; preload'
    'x-content-type-options': 'nosniff'
    'x-ms-region': 'REDACTED'
    'Date': 'Fri, 17 Mar 2023 11:08:18 GMT'
2023-03-17 19:08:19,565 |  INFO Request URL: 'https://pedimento.cognitiveservices.azure.com/formrecognizer/documentModels/PedimentoModelCopy/analyzeResults/590eb38b-87b0-44d5-bb5e-f719e94e52cb?api-version=2022-08-31'
Request method: 'GET'
Request headers:
    'x-ms-client-request-id': '0502a4f2-c4b4-11ed-b9d7-5414f3f87608'
    'User-Agent': 'azsdk-python-ai-formrecognizer/3.2.0 Python/3.9.1 (Windows-10-10.0.19041-SP0)'
    'Ocp-Apim-Subscription-Key': 'REDACTED'
No body was attached to the request
2023-03-17 19:08:19,835 |  INFO Response status: **200**
Response headers:
    'Content-Length': '106'
    'Content-Type': 'application/json; charset=utf-8'
    'x-envoy-upstream-service-time': '20'
    'apim-request-id': '0cc1299e-0c64-4540-998d-250691b456e3'
    'Strict-Transport-Security': 'max-age=31536000; includeSubDomains; preload'
    'x-content-type-options': 'nosniff'
    'x-ms-region': 'REDACTED'
    'Date': 'Fri, 17 Mar 2023 11:08:19 GMT'
2023-03-17 19:08:24,847 |  INFO Request URL: 'https://pedimento.cognitiveservices.azure.com/formrecognizer/documentModels/PedimentoModelCopy/analyzeResults/590eb38b-87b0-44d5-bb5e-f719e94e52cb?api-version=2022-08-31'
Request method: 'GET'
Request headers:
    'x-ms-client-request-id': '0502a4f2-c4b4-11ed-b9d7-5414f3f87608'
    'User-Agent': 'azsdk-python-ai-formrecognizer/3.2.0 Python/3.9.1 (Windows-10-10.0.19041-SP0)'
    'Ocp-Apim-Subscription-Key': 'REDACTED'
No body was attached to the request
2023-03-17 19:08:25,136 |  INFO Response status: **200**
Response headers:
    'Content-Length': '106'
    'Content-Type': 'application/json; charset=utf-8'
    'x-envoy-upstream-service-time': '34'
    'apim-request-id': 'd51bd641-e9e1-4771-b408-ad2d0757e79a'
    'Strict-Transport-Security': 'max-age=31536000; includeSubDomains; preload'
    'x-content-type-options': 'nosniff'
    'x-ms-region': 'REDACTED'
    'Date': 'Fri, 17 Mar 2023 11:08:24 GMT'
2023-03-17 19:08:30,142 |  INFO Request URL: 'https://pedimento.cognitiveservices.azure.com/formrecognizer/documentModels/PedimentoModelCopy/analyzeResults/590eb38b-87b0-44d5-bb5e-f719e94e52cb?api-version=2022-08-31'
Request method: 'GET'
Request headers:
    'x-ms-client-request-id': '0502a4f2-c4b4-11ed-b9d7-5414f3f87608'
    'User-Agent': 'azsdk-python-ai-formrecognizer/3.2.0 Python/3.9.1 (Windows-10-10.0.19041-SP0)'
    'Ocp-Apim-Subscription-Key': 'REDACTED'
No body was attached to the request
2023-03-17 19:08:30,886 |  INFO Response status: **200**
Response headers:
    'Content-Length': '104423'
    'Content-Type': 'application/json; charset=utf-8'
    'x-envoy-upstream-service-time': '47'
    'apim-request-id': '7c29a2a6-ccf0-48aa-a072-af374bb32794'
    'Strict-Transport-Security': 'max-age=31536000; includeSubDomains; preload'
    'x-content-type-options': 'nosniff'
    'x-ms-region': 'REDACTED'
    'Date': 'Fri, 17 Mar 2023 11:08:29 GMT'

SDK返回结果

documents=[AnalyzedDocument(doc_type=******, bounding_regions=[BoundingRegion(page_number=1, polygon=[Point(x=0.0, y=0.0), Point(x=8.5, y=0.0), Point(x=8.5, y=11.0), Point(x=0.0, y=11.0)])], spans=[DocumentSpan(offset=0, length=3233)], fields={'Total Impuestos': DocumentField(value_type=string, value='8000 8036', content=8000
8036, bounding_regions=[BoundingRegion(page_number=1, polygon=[Point(x=3.0062, y=3.3237), Point(x=3.7402, y=3.3237), Point(x=3.7402, y=3.3762), Point(x=3.0062, y=3.3762)])], spans=[DocumentSpan(offset=1867, length=9)], confidence=0.246), 'CVE': DocumentField(value_type=string, value=**None**, content=None, bounding_regions=[], spans=[], confidence=0.619), 'Num Pedimento': DocumentField(value_type=string, value=**None**, content=None, bounding_regions=[], spans=[], confidence=0.255), 'Modalid': DocumentField(value_type=string, value=**None**, content=None, bounding_regions=[], spans=[], confidence=0.638), 'Aduana': DocumentField(value_type=string, value=**None**, content=None, bounding_regions=[], spans=[], confidence=0.488), 'Fecha': DocumentField(value_type=date, value=**None**, content=None, bounding_regions=[], spans=[], confidence=0.617), 'Valor Aduana': DocumentField(value_type=string, value=**None**, content=None, bounding_regions=[], spans=[], confidence=0.635)}, confidence=0.001)])

获取文档模型响应

DocumentModelDetails(model_id=PedimentoModel, description=Mexcio Ops | Novum Imports | Pedimento Forms, created_on=2023-02-27 07:54:29+00:00, api_version=2022-08-31, tags={}, doc_types={'PedimentoModel': DocumentTypeDetails(description=None, build_mode=neural, field_schema={'Num Pedimento': {'type': 'string'}, 'CVE': {'type': 'string'}, 'Aduana': {'type': 'string'}, 'Modalid': {'type': 'string'}, 'Valor Aduana': {'type': 'string'}, 'Fecha': {'type': 'date'}, 'Total Impuestos': {'type': 'string'}}, field_confidence={})})

排查解决步骤

  • 核对调用的模型实例:日志显示调用的是PedimentoModelCopy,但获取的模型详情是PedimentoModel,确认是否误调用了复制后的模型,检查复制模型是否完成重新训练,或是否存在配置差异。
  • 修正locale参数:文档是墨西哥海关文件(Pedimento),SDK调用时指定了locale=en,尝试改为es-MX,避免语言识别偏差导致字段提取失败。
  • 验证输入文档一致性:确保SDK传入的文档与Studio测试的是完全相同的文件,检查文档是否存在编码、PDF版本、扫描清晰度等差异,必要时重新保存文档后再调用。
  • 升级SDK版本:当前使用的是azsdk-python-ai-formrecognizer/3.2.0,升级到最新稳定版,排查版本兼容性问题。
  • 检查模型状态:登录Form Recognizer Studio,确认PedimentoModelCopy的训练状态、训练数据是否有变更,若模型损坏或训练数据异常,重新训练模型。
  • 对比请求参数:通过浏览器开发者工具捕获Studio测试时的API请求参数,与SDK的请求参数逐一对比,确保pages、stringIndexType等参数完全一致。

内容的提问来源于stack exchange,提问作者kim16

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.27 17:19:52