Form Recognizer API with Python for PDF throwing "BadArgument" error
还没有人认领这个 Issue。
评估
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 新手友好度
- 30/100
- Issue 类型
- 缺陷
- 描述清晰度
- 需要澄清
- 活跃度
- 停滞
- 技术栈
- python
- 领域
- api, documentation
调研方向
首先按照“Extract text and layout information using the Form Recognizer REST API with Python” Quickstart 操作,并将其请求与失败的 get_url 函数以及报告中的 Form Recognizer v2.1 endpoint 进行比较。使用提供的 PDF 请求重现 BadArgument 响应,然后验证修正后的 Quickstart 能够在不出现错误的情况下返回操作 URL。
由索引模型根据 Issue 内容生成。
描述
The issue
The Quickstart for Form Recognizer REST API with Python is not functioning any more. It throws the following error:
POST analyze failed:
{"error":{"code":"BadArgument","message":"Bad or unrecognizable request JSON or binary file."}}
Not sure if this has to do with the update to Form Recognizer REST API v3.0, but is not functioning for PDF anymore. It worked a few weeks ago.
My code
from requests import get, post, Request, Session
endpoint = r"https://westeurope.api.cognitive.microsoft.com"
key = "<my_personal_key"
source = r"<path to pdf>"
def get_url(filename, endpoint, apim_key):
# v2.1
post_url = endpoint + "/formrecognizer/v2.1/layout/analyze"
headers = {
# Request headers
'Content-Type': 'application/pdf',
'Ocp-Apim-Subscription-Key': apim_key,
}
with open(filename, "rb") as f:
data_bytes = f.read()
try:
resp = post(post_url, data=data_bytes, headers=headers)
if resp.status_code != 202:
print("POST analyze failed:\n%s" % resp.text)
return None
print("POST analyze succeeded: %s" % resp.headers["operation-location"])
get_url = resp.headers["operation-location"]
return get_url
except Exception as e:
print("POST request failed:\n%s" % str(e))
return None
resp_url = get_url(source, endpoint, key)
This issue is for a: (mark with an x)
- [ ] bug report -> please search issues before submitting
- [ ] feature request
- [ ] documentation issue or request
- [x] regression (a behavior that used to work and stopped in a new release)
Minimal steps to reproduce
Follow the Quickstart: Extract text and layout information using the Form Recognizer REST API with Python
Any log messages given by the failure
POST analyze failed:
{"error":{"code":"BadArgument","message":"Bad or unrecognizable request JSON or binary file."}}
Expected/desired behavior
I would expect to get a url returned
OS and Version?
Working on Windows 10, using Visual Studio Code
Versions
requests == 2.28.1
Python == 3.9.13
- 主要语言
- Jupyter Notebook
- 星标
- 388
- 派生
- 555
- PR 合并指标
- 30 天内没有已合并 PR
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
Azure-Samples/cognitive-services-quickstart-code 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 25/100
-
难度 3/5 1-2 天 新手友好度 25/100
Azure-Samples/cognitive-services-quickstart-code#346 · 1 条评论 ·
-
难度 4/5 3-5 天 新手友好度 35/100
-
难度 3/5 1-2 天 新手友好度 25/100
-
难度 3/5 1-2 天 新手友好度 25/100
查看 Azure-Samples/cognitive-services-quickstart-code 的全部 Issue
相似的 Issue
-
[Bug] dubbo.protocol.triple.max-message-size is only read from OS environment variables可能已有人在做 @CCCLL 今天认领。 未关闭
难度 2/5 1-3 小时 新手友好度 72/100
维护者通常 1 天内回复
-
domain/discovery
难度 2/5 1-3 小时 新手友好度 88/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 76/100
维护者通常 1 天内回复
-
nonews refactor
难度 2/5 1-3 小时 新手友好度 75/100
Uninett/nav#4255 · 1 条评论 · 1 个 reaction ·
维护者通常 3 天内回复
-
难度 2/5 1-3 小时 新手友好度 64/100
hierynomus/sshj#1070 ·