Azure Computer Vision / Read API: readingOrder=natural fails with Internal server error

Barbaros Özdemir 1 Reputation point
2022-03-29T22:31:08.147+00:00

my resource is located in GermanyWest region. To reproduce this issue I used a sample PDF file from " https://www.acm.org/binaries/content/assets/publications/word_style/interim-template-style/interim-layout.pdf ":

Send a REST Call to Read API endpoint, where you upload a PDF file;

curl --location --request POST 'https://<REPLACEWITHYOURRESOURCENAME>.cognitiveservices.azure.com/vision/v3.2/read/analyze?readingOrder=natural' \
--header 'Content-Type: application/octet-stream' \
--header 'Ocp-Apim-Subscription-Key: <REPLACEWITHYOUROWNKEY>' \
--data-binary '@/C:/Users/Barbaros Oezdemir/Desktop/interim-layout.pdf'

Response Status is 202. So far so good. Next, make the next REST Call to the URL returned in header to get the result;

curl --location --request GET 'https://<REPLACEWITHYOURRESOURCENAME>.cognitiveservices.azure.com/vision/v3.2/read/analyzeResults/ec2ea347-c4f4-416a-9d8d-a3e76cbb2b16' \
--header 'Content-Type: application/json' \
--header 'Ocp-Apim-Subscription-Key: <REPLACEWITHYOUROWNKEY>' \

The response status is 200 OK

The response body is:

{
"status": "failed",
"createdDateTime": "2022-03-29T22:02:31Z",
"lastUpdatedDateTime": "2022-03-29T22:02:31Z",
"analyzeResult": {
"version": "",
"readResults": [],
"errors": [
{
"code": "Unspecified",
"message": "Internal server error."
}
]
}
}

Computer Vision
Computer Vision
An Azure artificial intelligence service that analyzes content in images and video.
417 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. romungi-MSFT 48,911 Reputation points Microsoft Employee Moderator
    2022-03-30T09:12:17.11+00:00

    @Barbaros Özdemir The image here is passed with application/octet-stream header but the actual data passed in body is not binary data but instead a local file reference. This call will not pass the binary data. You need to pass the streaming data or actual binary data by reading the file, For example: With python you can read the file and call the API.

    image_data = open(image_path, "rb").read()  
    headers = {'Ocp-Apim-Subscription-Key': subscription_key,  
               'Content-Type': 'application/octet-stream'}  
    params = {'visualFeatures': 'Categories,Description,Color'}  
    response = requests.post(  
        analyze_url, headers=headers, params=params, data=image_data)  
    response.raise_for_status()  
      
    # The 'analysis' object contains various fields that describe the image. The most  
    # relevant caption for the image is obtained from the 'description' property.  
    analysis = response.json()  
    print(analysis)  
    

    Full sample available here.

    Since you already have the file as URI you can use the same in body of the request instead of downloading the file to local.
    Example:

    curl -H "Ocp-Apim-Subscription-Key: <subscriptionKey>" -H "Content-Type: application/json" "<your_endpoint>/vision/v3.2/analyze -d "{\"url\":\"https://www.acm.org/binaries/content/assets/publications/word_style/interim-template-style/interim-layout.pdf\"}"  
    

    UPDATE:
    Below call to pass the local file should also work, the error in this case seems to be with the parameter as mentioned in further comments below:

    curl --location --request POST "https://<your-resource>.cognitiveservices.azure.com/vision/v3.2/read/analyze?readingOrder=basic" --header "Content-Type: application/octet-stream" --header "Ocp-Apim-Subscription-Key: <your_key>" --data-binary "@/C:\\Users\\test\\Documents\\interim-layout.pdf"  
    

    If an answer is helpful, please click on 130616-image.png or upvote 130671-image.png which might help other community members reading this thread.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.