Skip to content

Resource not found - 404 #45441

Open
Open
@tfierens

Description

@tfierens

Library name and version

Azure.AI.DocumentIntelligence 1.0.0-beta.2

Describe the bug

Request failed: Resource not found
Status: 404 (Not Found)
ErrorCode: 404

Expected behavior

Access the Document Intelligence service, process the document I passed and return my the relevant fields.

Actual behavior

This is the full output to my console:

[Informational] Azure-Core: Request [a8ef754b-b47a-4a68-8930-7c4b7dfaeb34] POST https://.cognitiveservices.azure.com/documentintelligence/documentModels/model1:analyze?api-version=2024-02-29-preview
Accept:application/json
content-type:application/json
x-ms-client-request-id:a8ef754b-b47a-4a68-8930-7c4b7dfaeb34
x-ms-return-client-request-id:true
User-Agent:azsdk-net-AI.DocumentIntelligence/1.0.0-beta.2 (.NET Framework 4.8.9261.0; Microsoft Windows 10.0.22631 )
Ocp-Apim-Subscription-Key:REDACTED
client assembly: Azure.AI.DocumentIntelligence
[Warning] Azure-Core: Error response [a8ef754b-b47a-4a68-8930-7c4b7dfaeb34] 404 Not Found (00.2s)
Content-Length:55
Content-Type:application/json
Date:Fri, 09 Aug 2024 11:24:53 GMT

Request failed: Resource not found
Status: 404 (Not Found)
ErrorCode: 404

Content:
{"error":{"code":"404","message":"Resource not found"}}

Headers:
Content-Length: 55
Content-Type: application/json
Date: Fri, 09 Aug 2024 11:24:53 GMT

Status: 404
ErrorCode: 404

Reproduction Steps

I got my endpoint and api key from the Azure portal and confirmed it via the CLI and they are definitely set correctly.

This is the code I'm using:

    static void Main(string[] args)
    {
        var endpoint = "https://<myinstance>.cognitiveservices.azure.com/";
        var apiKey = "<myapikey>";
        var filename = "<myfile>.jpg";

        var client = new DocumentIntelligenceClient(new Uri(endpoint), new AzureKeyCredential(apiKey));

        try
        {
            using (AzureEventSourceListener listener = AzureEventSourceListener.CreateConsoleLogger())
            {
                using (var stream = new FileStream(filename, FileMode.Open))
                {
                    var result = AnalyzeDocumentAsync(client, stream).GetAwaiter().GetResult();
                    Console.WriteLine(result);
                }
            }
        }
        catch (RequestFailedException ex)
        {
            Console.WriteLine($"Request failed: {ex.Message}");
            Console.WriteLine($"Status: {ex.Status}");
            Console.WriteLine($"ErrorCode: {ex.ErrorCode}");
        }
        catch (Exception ex)
        {
            Console.WriteLine($"An error occurred: {ex.Message}");
        }

        Console.ReadLine();
    }

    static async Task<Operation<AnalyzeResult>> AnalyzeDocumentAsync(DocumentIntelligenceClient client, Stream documentStream)
    {
        /*
          This code sample shows Custom Model operations with the Azure Form Recognizer client library. 

          To learn more, please visit the documentation - Quickstart: Document Intelligence (formerly Form Recognizer) SDKs
          https://learn.microsoft.com/azure/ai-services/document-intelligence/quickstarts/get-started-sdks-rest-api?pivots=programming-language-csharp
        */

        /*
          Remember to remove the key from your code when you're done, and never post it publicly. For production, use
          secure methods to store and access your credentials. For more information, see 
          https://docs.microsoft.com/en-us/azure/cognitive-services/cognitive-services-security?tabs=command-line%2Ccsharp#environment-variables-and-application-configuration
        */

        //AzureKeyCredential credential = new AzureKeyCredential(apiKey);
        //DocumentAnalysisClient client = new DocumentAnalysisClient(new Uri(endpoint), credential);

        string modelId = "model1";

        var content = new AnalyzeDocumentContent()
        {
            Base64Source = BinaryData.FromStream(documentStream)
        };

        //Uri fileUri = new Uri("https://raw.githubusercontent.com/Azure-Samples/cognitive-services-REST-api-samples/master/curl/form-recognizer/sample-layout.pdf");

        //AnalyzeDocumentContent content = new AnalyzeDocumentContent()
        //{
        //    UrlSource = fileUri
        //};

        //var operation = await client.AnalyzeDocumentAsync(WaitUntil.Completed, modelId, content);
        var operation = await client.AnalyzeDocumentAsync(WaitUntil.Completed, modelId, content);

        AnalyzeResult result = operation.Value;

        Console.WriteLine($"Document was analyzed with model with ID: {result.ModelId}");

        foreach (AnalyzedDocument document in result.Documents)
        {
            Console.WriteLine($"Document of type: {document.DocType}");

            foreach (KeyValuePair<string, DocumentField> fieldKvp in document.Fields)
            {
                string fieldName = fieldKvp.Key;
                DocumentField field = fieldKvp.Value;

                Console.WriteLine($"Field '{fieldName}': ");

                Console.WriteLine($"  Content: '{field.Content}'");
                Console.WriteLine($"  Confidence: '{field.Confidence}'");
            }
        }

        // Iterate over lines and selection marks on each page
        foreach (DocumentPage page in result.Pages)
        {
            Console.WriteLine($"Lines found on page {page.PageNumber}");
            foreach (var line in page.Lines)
            {
                Console.WriteLine($"  {line.Content}");
            }

            Console.WriteLine($"Selection marks found on page {page.PageNumber}");
            foreach (var selectionMark in page.SelectionMarks)
            {
                Console.WriteLine($"  Selection mark is '{selectionMark.State}' with confidence {selectionMark.Confidence}");
            }
        }

        // Iterate over the document tables
        for (int i = 0; i < result.Tables.Count; i++)
        {
            Console.WriteLine($"Table {i + 1}");
            foreach (var cell in result.Tables[i].Cells)
            {
                Console.WriteLine($"  Cell[{cell.RowIndex}][{cell.ColumnIndex}] has content '{cell.Content}' with kind '{cell.Kind}'");
            }
        }

        return operation;
    }

Environment

.net 4.8.1 in a console application
c# in .NET Studio 2022
Azure.AI.DocumentIntelligence 1.0.0-beta.2

Metadata

Metadata

Assignees

Labels

ClientThis issue points to a problem in the data-plane of the library.Cognitive - Form Recognizercustomer-reportedIssues that are reported by GitHub users external to the Azure organization.questionThe issue doesn't require a change to the product in order to be resolved. Most issues start as that

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions