Keep Getting Error Could not connect to upstream host: Error while copying content to a stream

Shailesh Kumar (NAV Backoffice) 25 Reputation points
2024-03-08T14:51:09.75+00:00

I am using below code to perform OCR using the connected container hosted environment .

from azure.ai.formrecognizer import DocumentAnalysisClient
from azure.core.credentials import AzureKeyCredential
credential = AzureKeyCredential("KEY")
client = DocumentAnalysisClient(endpoint="http://domain:5000/", credential=credential)
document_path = "D:\passport.png"
with open(document_path, "rb") as file:
    document_bytes = file.read()
operation = client.begin_analyze_document("prebuilt-idDocument", document_bytes, api_version="2022-08-31")
result = operation.result()
print(result)

Getting below error

(InternalServerError) An unexpected error occurred.
Code: InternalServerError
Message: An unexpected error occurred.
Exception Details:	(HttpRequestException) Could not connect to upstream host: Error while copying content to a stream.

When I checked the container logs I found below error, but not getting what is the actual reason for the error.

      {"ClassName":"Microsoft.CloudAI.Containers.VDI.Common.Errors.VdiException","Message":"HttpRequestException","Data":null,"InnerException":null,"HelpURL":null,"StackTraceString":"   at Microsoft.CloudAI.Containers.VDI.OnPremises.Common.Handler.FrBaseHandler.HttpPostAsync(String requestUri, HttpContent content)\n   at Microsoft.CloudAI.Containers.VDI.OnPremises.Common.Handler.Fr30GaUpstreamHandler.PostUpstreamInternalRequest(String modelId, Byte[] stream, ServiceMessage message)\n   at Microsoft.CloudAI.Containers.VDI.OnPremises.Common.Handler.Fr30GaUpstreamHandler.HandleMessageAsync(ServiceMessage message)","RemoteStackTraceString":null,"RemoteStackIndex":0,"ExceptionMethod":null,"HResult":-2146233088,"Source":"Microsoft.CloudAI.Containers.VDI.OnPremises.Common","WatsonBuckets":null} SubscriptionId='' RequestId='57a024ea-c5a9-44f0-8af3-a0721d772f27' Timestamp='' buildVersion='1.2.367.0-20230707.6-27dcd7ae972075713bb9e4477fe50c6e623f1596' hostId='9191b2644d80' serviceName='formrecognizerid' namespace='vdi' Namesapce='vdi' fileSizeInBytes='2380079' processedPageIndex='0' toSecondaryQueue='False' totalPageCount='1' fileType='Jpeg' apiName='idDocument-2022-08-31' ocrModelName='2023-07-31' scenario='fr_async_read' resultNameEnum='UpstreamFRResult' ocrResolution='Standard' errorCode='HttpRequestException'
fail: formrecognizerid[0]

Azure AI Document Intelligence
Azure AI Document Intelligence
An Azure service that turns documents into usable data. Previously known as Azure Form Recognizer.
1,505 questions
{count} votes