admin管理员组文章数量:1124799
I have the following Python code to extract text from a locally stored PDF file:
# import libraries
import os
from azure.core.credentials import AzureKeyCredential
from azure.ai.documentintelligence import DocumentIntelligenceClient
from azure.ai.documentintelligence.models import AnalyzeResult
from azure.ai.documentintelligence.models import AnalyzeDocumentRequest
import base64
def analyze_layout():
document_intelligence_client = DocumentIntelligenceClient(
endpoint="https://<resource-name>.cognitiveservices.azure/",
credential=AzureKeyCredential("EHCGTC....")
)
with open("C:/Users/lvg/source/repos/terraform-ai-iac/terraform-ai-iac/data/documents/test.pdf", "rb") as document:
poller = document_intelligence_client.begin_analyze_document("prebuilt-layout", document)
result: AnalyzeResult = poller.result()
analyze_layout()
However, when I run this code I get the error:
azure.core.exceptions.ResourceNotFoundError: (404) Resource not found
Code: 404
Message: Resource not found
I am able to go to the resource in Azure and use document intelligence there to extract the text from the PDF that is stored locally.
What could be the reason my code is not working?
I have the following Python code to extract text from a locally stored PDF file:
# import libraries
import os
from azure.core.credentials import AzureKeyCredential
from azure.ai.documentintelligence import DocumentIntelligenceClient
from azure.ai.documentintelligence.models import AnalyzeResult
from azure.ai.documentintelligence.models import AnalyzeDocumentRequest
import base64
def analyze_layout():
document_intelligence_client = DocumentIntelligenceClient(
endpoint="https://<resource-name>.cognitiveservices.azure.com/",
credential=AzureKeyCredential("EHCGTC....")
)
with open("C:/Users/lvg/source/repos/terraform-ai-iac/terraform-ai-iac/data/documents/test.pdf", "rb") as document:
poller = document_intelligence_client.begin_analyze_document("prebuilt-layout", document)
result: AnalyzeResult = poller.result()
analyze_layout()
However, when I run this code I get the error:
azure.core.exceptions.ResourceNotFoundError: (404) Resource not found
Code: 404
Message: Resource not found
I am able to go to the resource in Azure and use document intelligence there to extract the text from the PDF that is stored locally.
What could be the reason my code is not working?
Share Improve this question asked 2 days ago Luuk van GasterenLuuk van Gasteren 133 bronze badges 4 |1 Answer
Reset to default 0azure.core.exceptions.ResourceNotFoundError: (404) Resource not found Code: 404 Message: Resource not found.
"The error might be due to the location, API version, or SDK version being used. If you used correct endpoint and key.
In my environment, I used SDK with azure-ai-documentintelligence==1.0.0
version and I deployed my Document intelligence studio in east us
with standard
tier.
Portal:
Now, I used the same code with correct endpoint and key from the portal.
Code:
from azure.core.credentials import AzureKeyCredential
from azure.ai.documentintelligence import DocumentIntelligenceClient
def analyze_layout():
document_intelligence_client = DocumentIntelligenceClient(
endpoint="https://venkatdoc45.cognitiveservices.azure.com/",
credential=AzureKeyCredential("xxxxx")
)
with open(r"C:\Downloads\test (1).pdf", "rb") as document:
poller = document_intelligence_client.begin_analyze_document("prebuilt-layout", document)
AnalyzeResult = poller.result()
print(AnalyzeResult.content)
analyze_layout()
Output:
Your Name
Lorem ipsum dolor sit amet, consectetuer adipiscing elit
EXPERIENCE
Company, Location - Job Title MONTH 20XX - PRESENT
Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh.
Company, Location - Job Title MONTH 20XX - MONTH 20XX
Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh.
Company, Location - Job Title MONTH 20XX - MONTH 20XX
Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh.
EDUCATION
School Name, Location - Degree MONTH 20XX - MONTH 20XX
Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore.
School Name, Location - Degree MONTH 20XX - MONTH 20XX
Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam.
PROJECTS
Reference: Azure AI Document Intelligence client library for Python | Microsoft Learn
本文标签: pythonAzure Document Intelligence beginanalyzedocument method errorStack Overflow
版权声明:本文标题:python - Azure Document Intelligence begin_analyze_document method error - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736635691a1945874.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
api
key is in correct? – Venkatesan Commented 2 days ago