Form Recognizer API with Python for PDF throwing "BadArgument" error
Dieses Issue hat noch niemand übernommen.
Bewertung
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Anfängerfreundlichkeit
- 30/100
- Issue-Typ
- Bug
- Klarheit
- Muss geklärt werden
- Aktivitätsstatus
- Veraltet
- Tech-Stack
- python
- Bereich
- api, documentation
Rechercherichtung
Beginne damit, dem „Extract text and layout information using the Form Recognizer REST API with Python“-Quickstart zu folgen und seine Anfrage mit der fehlschlagenden Funktion get_url sowie dem gemeldeten Form Recognizer v2.1-Endpunkt zu vergleichen. Reproduziere die BadArgument-Antwort anhand der bereitgestellten PDF-Anfrage und überprüfe anschließend, dass der korrigierte Quickstart ohne den Fehler eine Operations-URL zurückgibt.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
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
- Vorherrschende Sprache
- Jupyter Notebook
- Sterne
- 388
- Forks
- 556
- PR-Merge-Kennzahlen
- Keine gemergten PRs in 30 T.
Entwicklungsumgebung
- Kein Dockerfile und keine Docker-Compose-Datei
- Hat eine Pull-Request-Vorlage
- Beitragsleitfaden lesen
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus Azure-Samples/cognitive-services-quickstart-code
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 25/100
-
Schwierigkeit 3/5 1-2 Tage Anfängerfreundlichkeit 25/100
Azure-Samples/cognitive-services-quickstart-code#346 · 1 Kommentar ·
-
Schwierigkeit 4/5 3-5 Tage Anfängerfreundlichkeit 35/100
-
Schwierigkeit 3/5 1-2 Tage Anfängerfreundlichkeit 25/100
-
Schwierigkeit 3/5 1-2 Tage Anfängerfreundlichkeit 25/100
Alle Issues in Azure-Samples/cognitive-services-quickstart-code
Ähnliche Issues
-
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 88/100
pop-os/cosmic-comp#2956 ·
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 90/100
Maintainer antworten meist innerhalb von 1 Tag
-
GET rooms API returns 500 due to nonexistent Room.is_active attributeEvtl. vergeben @Mars-60 hat das heute übernommen. Offenbug
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 84/100
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 76/100
Maintainer antworten meist innerhalb von 3 Tagen
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 72/100
Chocobozzz/PeerTube#7832 ·
Maintainer antworten meist innerhalb von 3 Tagen