Python SDK 使用Azure Document intelligence报错(404) Resource not found

5 篇文章 0 订阅

最近项目需要使用到Azure Document intelligence,于是去做POC,但是发现最简单的demo跑的时候都会报这个错,解决了一下午终于搞定了,记录下。

首先是官方文档:
Quickstart: Document Intelligence (formerly Form Recognizer) client libraries - Azure AI services | Microsoft Learn

从Azure portal里面copy endpoint以及key 

然后是安装依赖

pip install azure-ai-documentintelligence==1.0.0b2

 最后是demo代码。这个PDF应该是公共可以访问的。

from azure.ai.documentintelligence import DocumentIntelligenceClient
from azure.ai.documentintelligence.models import AnalyzeDocumentRequest

from azure.core.credentials import AzureKeyCredential
 
# 设置端点和API密钥
endpoint = "<your_endpoint>"
key = "<your_key>"
 
# 创建DocumentAnalysisClient实例
client = DocumentIntelligenceClient(endpoint=endpoint, credential=AzureKeyCredential(key))
pdfUrl="https://raw.githubusercontent.com/Azure-Samples/cognitive-services-REST-api-samples/master/curl/form-recognizer/sample-layout.pdf"
data=AnalyzeDocumentRequest(url_source=pdfUrl)
poller = client.begin_analyze_document("prebuilt-layout",data )
result = poller.result()
 
# 输出分析结果
for page in result.pages:
    print(f"Page Number: {page.page_number}")
    for line in page.lines:
        print(f"Line: {line.content}")

然后我就一直报错:
 解决了一下午,终于解决了。

查到了居然是区域的问题,本来是不太相信的,

 抱着试一试的心态尝试去重新创建了个DI,我一开始是southeast Asia,新建了一个是East US的区域的DI,然后修改代码里面的endpoint和key。重新跑代码,居然成功了

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值