【发布时间】:2021-07-05 19:49:30
【问题描述】:
有关使用 Azure 表单识别器的文档似乎不清楚。发送我的请求的正确 ENDPOINT 是什么?
我正在使用 python 并按照文档使用表单识别器的预建收据模型,但没有得到预期的输出。我不确定我是否使用了正确的端点。我尝试了两件事:
- 阅读此tutorial,表明我需要在资源的概述页面中查找
<ENDPOINT>。就我而言,它是:formextractor.cognitiveservices.azure.com。所以我尝试了这个:
import http.client, urllib.request, urllib.parse, urllib.error, base64
params = urllib.parse.urlencode({
})
# key = '...'
headers = {
# Request headers
'Content-Type': 'application/json',
'Ocp-Apim-Subscription-Key': key,
}
source = r"https://www.w3.org/WAI/WCAG20/Techniques/working-examples/PDF20/table.pdf"
body = {"url":source}
body = json.dumps(body)
try:
conn = http.client.HTTPSConnection('formextractor.cognitiveservices.azure.com')
conn.request("POST", "/formrecognizer/v1.0-preview/prebuilt/receipt/asyncBatchAnalyze?s" % params, f"{body}", headers)
response = conn.getresponse()
data = response.read()
operationURL = "" + response.getheader("Operation-Location")
print ("Operation-Location header: " + operationURL)
conn.close()
except Exception as e:
print(e)
这会返回:
[Errno 8] nodename nor servname provided, or not known
- 但在API Docs 中,ENDPOINT 已经固定为
westeurope.api.cognitive.microsoft.com,这是我的资源所在的位置。所以我尝试了这个:
# ... same headers, body and params as before
try:
conn = http.client.HTTPSConnection('westeurope.api.cognitive.microsoft.com')
conn.request("POST", "/formrecognizer/v1.0-preview/prebuilt/receipt/asyncBatchAnalyze?%s" % params, f"{body}", headers)
response = conn.getresponse()
data = response.read()
operationURL = "" + response.getheader("Operation-Location")
print ("Operation-Location header: " + operationURL)
conn.close()
except Exception as e:
print("[Errno {0}] {1}".format(e.errno, e.strerror))
在我看到的地方输出一个 URL:
{"error":{"code":"401","message": "Access denied due to invalid subscription key or wrong API endpoint. Make sure to provide a valid key for an active subscription and use a correct regional API endpoint for your resource."}}
我确定我使用了正确的密钥。但无论如何,两者似乎都不起作用。你可以帮帮我吗?谢谢。
【问题讨论】:
标签: microsoft-cognitive azure-cognitive-services