I faced the same issue. I was able to solve the problem by changing the API version specified from “2023-07-31 (GA)” to “2024-07-31 (Preview)” when creating the custom model.
Form recognizer custom model - Python connection issue
William Peterson
0
Reputation points
I am trying to connect python to my custom form recognizer in order to pull data off of pdfs, but I am running into an error when I try to connect. I found my endpoint and key from Azure Portal, and I believed I could use the name of my model in Form Recognizer Studio, but this indicates otherwise. My project is called Entegrity-custom-parser and the Model ID inside that is called first_five_model. How can I fix this to connect?
Error:
azure.core.exceptions.ResourceNotFoundError: (NotFound) Resource not found.
Code: NotFound
Message: Resource not found.
Inner error: {
"code": "ModelNotFound",
"message": "The requested model was not found."
}
My code:
from azure.core.credentials import AzureKeyCredential
from azure.ai.formrecognizer import DocumentAnalysisClient
def pdf_to_bytes(file_path):
with open(file_path, 'rb') as file:
pdf_bytes = file.read()
return pdf_bytes
endpoint = 'https://southcentralus.api.cognitive.microsoft.com/'
key = ''
custom_model_id = 'first_five_model'
path = 'C:/Users/william.peterson/Desktop/training-files/normal.pdf'
document_analysis_client = DocumentAnalysisClient(
endpoint=endpoint, credential=AzureKeyCredential(key)
)
poller = document_analysis_client.begin_analyze_document(custom_model_id, pdf_to_bytes(path))
invoices = poller.result()
for idx, invoice in enumerate(invoices.documents):
print(idx,invoice)