0

我有以下控制台应用程序(.net core 5.0):

class Program
{
    static void Main(string[] args)
    {
        var test = Test();
        Task.WaitAll(test);
    }

    private static async Task Test()
    {
        Console.WriteLine("Start using Azure Form Recognizer ...");

        var endpoint = "https://my-formrecognizer.cognitiveservices.azure.com/";
        var apiKey = "my-api-key";

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

        var invoiceUri = new Uri("SAS-URI-to-my-invoice-pdf-blob");

        FormPageCollection formPages = await client
            .StartRecognizeContentFromUri(invoiceUri)
            .WaitForCompletionAsync();

        if (formPages != null)
        {
            Console.WriteLine("Got Form Recognizer working");
        }
        else
        {
            Console.WriteLine("Something is wrong here");
        }
    }
}

我从我的 WIndows 10 PC 上执行了上述控制台应用程序,如下所示:

dotnet FormRecognizerTest.dll

它按预期工作;我的控制台上打印了“让表单识别器正常工作”这一行。

现在我在 Azure VM(Ubuntu 20.04)上执行了相同的应用程序,如下所示:

sudo dotnet FormRecognizerTest.dll

但是,这一次它打印了“开始使用 Azure 表单识别器 ...”,过了一段时间它抛出了以下错误:

开始使用 Azure 表单识别器...未处理的异常。System.AggregateException:发生一个或多个错误。(重试4次失败。重试设置可以在ClientOptions.Retry中调整。(资源暂时不可用(my-formrecognizer.cognitiveservices.azure.com:443))(资源暂时不可用(my-formrecognizer.cognitiveservices.azure.com: 443)) (资源暂时不可用 (my-formrecognizer.cognitiveservices.azure.com:443)) (资源暂时不可用 (my-formrecognizer.cognitiveservices.azure.com:443))) ---> System.AggregateException: 重试失败4 次尝试后。可以在 ClientOptions.Retry 中调整重试设置。(资源暂时不可用 (my-formrecognizer.cognitiveservices.azure.com:443)) (资源暂时不可用 (my-formrecognizer.cognitiveservices.azure.com:

--->(内部异常 #2)Azure.RequestFailedException:资源暂时不可用(my-formrecognizer.cognitiveservices.azure.com:443)---> System.Net.Http.HttpRequestException:资源暂时不可用(my-formrecognizer.认知服务.azure.com:443) ---> System.Net.Internals.SocketExceptionFactory+ExtendedSocketException (00000001, 11): System.Net 的 System.Net.Dns.GetHostEntryOrAddressesCore(String hostName, Boolean justAddresses) 的资源暂时不可用。 Dns.GetHostAddresses(String hostNameOrAddress) at System.Net.Sockets.Socket.Connect(String host, Int32 port) at System.Net.Sockets.Socket.Connect(EndPoint remoteEP) at System.Net.Http.ConnectHelper.Connect(String主机,Int32 端口,CancellationToken cancelToken) --- 内部异常堆栈跟踪结束 --- 在 System.Net.Http.ConnectHelper。在 System.Net.Http.HttpConnectionPool.ConnectToTcpHostAsync 连接(字符串主机,Int32 端口,CancellationToken cancelToken)(字符串主机,Int32 端口,HttpRequestMessage 初始请求,布尔异步,CancellationToken 取消令牌) --- 来自先前位置的堆栈跟踪结束 ---在 System.Net.Http.HttpConnectionPool.ConnectAsync(HttpRequestMessage 请求,布尔异步,CancellationToken 取消令牌)在 System.Net.Http.HttpConnectionPool.CreateHttp11ConnectionAsync(HttpRequestMessage 请求,布尔异步,CancellationToken 取消令牌)在 System.Net.Http.HttpConnectionPool.GetHttpConnectionAsync System.Net.Http.HttpConnectionPool.SendWithRetryAsync(HttpRequestMessage 请求,布尔异步,布尔 doRequestAuth,System.Net.Http.HttpMessageHandlerStage.Send(HttpRequestMessage 请求,CancellationToken cancelToken)在 System.Net.Http.SocketsHttpHandler.Send System.Net.Http.HttpClient.SendAsyncCore 的 System.Net.Http.HttpMessageInvoker.Send 的(HttpRequestMessage 请求,CancellationToken 取消令牌)(HttpRequestMessage 请求,CancellationToken 取消令牌)(HttpRequestMessage 请求,HttpCompletionOption 完成选项,布尔异步,布尔型 emitTelemetryStartStop,CancellationToken 取消令牌)在 Azure.Core.Pipeline 的 System.Net.Http.HttpClient.Send(HttpRequestMessage 请求,HttpCompletionOption 完成选项,CancellationToken 取消令牌)。HttpClientTransport.ProcessAsync(HttpMessage message, Boolean async) --- 内部异常堆栈跟踪结束 --- Azure.Core.Pipeline.HttpClientTransport.ProcessAsync(HttpMessage message, Boolean async) 在 Azure.Core.Pipeline.TaskExtensions.EnsureCompleted( ValueTask task)在 Azure.Core.Pipeline.HttpClientTransport.Process(HttpMessage message) 在 Azure.Core.Pipeline.HttpPipelineTransportPolicy.Process(HttpMessage message, ReadOnlyMemory1 pipeline) 在 Azure.Core.Pipeline.HttpPipelinePolicy.ProcessNext(HttpMessage message, ReadOnlyMemory1 pipeline ) Azure.Core.Pipeline.RequestActivityPolicy.ProcessNextAsync(HttpMessage message, ReadOnlyMemory1 pipeline, Boolean async) at Azure.Core.Pipeline.RequestActivityPolicy.Process(HttpMessage message, ReadOnlyMemory1 pipeline) at Azure.Core.Pipeline.HttpPipelinePolicy.ProcessNext(HttpMessage信息,Azure.Core.Pipeline.TaskExtensions.EnsureCompleted(ValueTask task) 在 Azure.Core.Pipeline.ResponseBodyPolicy.ProcessAsync(HttpMessage message, ReadOnlyMemory1 pipeline, Boolean async) 在 Azure.Core.Pipeline.ResponseBodyPolicy.Process(HttpMessage 消息的 ReadOnlyMemory1 管道) , ReadOnlyMemory1 管道) 在 Azure.Core.Pipeline.HttpPipelinePolicy.ProcessNext(HttpMessage 消息, ReadOnlyMemory1 管道) 在 Azure.Core.Pipeline.LoggingPolicy.Process(HttpMessage 消息, ReadOnlyMemory1 管道) 在 Azure.Core.Pipeline.HttpPipelinePolicy.ProcessNext(HttpMessage消息,ReadOnlyMemory1 管道)在 Azure.Core.Pipeline.HttpPipelineSynchronousPolicy.Process(HttpMessage 消息,ReadOnlyMemory1 管道)在 Azure.Core.Pipeline.HttpPipelinePolicy.ProcessNext(HttpMessage 消息,ReadOnlyMemory1 管道)在 Azure.Core.Pipeline.RetryPolicy。ProcessAsync(HttpMessage消息,ReadOnlyMemory`1管道,布尔异步)<---

--->(内部异常 #3)Azure.RequestFailedException:资源暂时不可用(my-formrecognizer.cognitiveservices.azure.com:443)---> System.Net.Http.HttpRequestException:资源暂时不可用(my-formrecognizer.认知服务.azure.com:443) ---> System.Net.Internals.SocketExceptionFactory+ExtendedSocketException (00000001, 11): System.Net 的 System.Net.Dns.GetHostEntryOrAddressesCore(String hostName, Boolean justAddresses) 的资源暂时不可用。 Dns.GetHostAddresses(String hostNameOrAddress) at System.Net.Sockets.Socket.Connect(String host, Int32 port) at System.Net.Sockets.Socket.Connect(EndPoint remoteEP) at System.Net.Http.ConnectHelper.Connect(String主机,Int32 端口,CancellationToken cancelToken) --- 内部异常堆栈跟踪结束 --- 在 System.Net.Http.ConnectHelper。在 System.Net.Http.HttpConnectionPool.ConnectToTcpHostAsync 连接(字符串主机,Int32 端口,CancellationToken cancelToken)(字符串主机,Int32 端口,HttpRequestMessage 初始请求,布尔异步,CancellationToken 取消令牌) --- 来自先前位置的堆栈跟踪结束 ---在 System.Net.Http.HttpConnectionPool.ConnectAsync(HttpRequestMessage 请求,布尔异步,CancellationToken 取消令牌)在 System.Net.Http.HttpConnectionPool.CreateHttp11ConnectionAsync(HttpRequestMessage 请求,布尔异步,CancellationToken 取消令牌)在 System.Net.Http.HttpConnectionPool.GetHttpConnectionAsync System.Net.Http.HttpConnectionPool.SendWithRetryAsync(HttpRequestMessage 请求,布尔异步,布尔 doRequestAuth,System.Net.Http.HttpMessageHandlerStage.Send(HttpRequestMessage 请求,CancellationToken cancelToken)在 System.Net.Http.SocketsHttpHandler.Send System.Net.Http.HttpClient.SendAsyncCore 的 System.Net.Http.HttpMessageInvoker.Send 的(HttpRequestMessage 请求,CancellationToken 取消令牌)(HttpRequestMessage 请求,CancellationToken 取消令牌)(HttpRequestMessage 请求,HttpCompletionOption 完成选项,布尔异步,布尔型 emitTelemetryStartStop,CancellationToken 取消令牌)在 Azure.Core.Pipeline 的 System.Net.Http.HttpClient.Send(HttpRequestMessage 请求,HttpCompletionOption 完成选项,CancellationToken 取消令牌)。HttpClientTransport.ProcessAsync(HttpMessage message, Boolean async) --- 内部异常堆栈跟踪结束 --- Azure.Core.Pipeline.HttpClientTransport.ProcessAsync(HttpMessage message, Boolean async) 在 Azure.Core.Pipeline.TaskExtensions.EnsureCompleted( ValueTask task)在 Azure.Core.Pipeline.HttpClientTransport.Process(HttpMessage message) 在 Azure.Core.Pipeline.HttpPipelineTransportPolicy.Process(HttpMessage message, ReadOnlyMemory1 pipeline) 在 Azure.Core.Pipeline.HttpPipelinePolicy.ProcessNext(HttpMessage message, ReadOnlyMemory1 pipeline ) Azure.Core.Pipeline.RequestActivityPolicy.ProcessNextAsync(HttpMessage message, ReadOnlyMemory1 pipeline, Boolean async) at Azure.Core.Pipeline.RequestActivityPolicy.Process(HttpMessage message, ReadOnlyMemory1 pipeline) at Azure.Core.Pipeline.HttpPipelinePolicy.ProcessNext(HttpMessage信息,Azure.Core.Pipeline.TaskExtensions.EnsureCompleted(ValueTask task) 在 Azure.Core.Pipeline.ResponseBodyPolicy.ProcessAsync(HttpMessage message, ReadOnlyMemory1 pipeline, Boolean async) 在 Azure.Core.Pipeline.ResponseBodyPolicy.Process(HttpMessage 消息的 ReadOnlyMemory1 管道) , ReadOnlyMemory1 管道) 在 Azure.Core.Pipeline.HttpPipelinePolicy.ProcessNext(HttpMessage 消息, ReadOnlyMemory1 管道) 在 Azure.Core.Pipeline.LoggingPolicy.Process(HttpMessage 消息, ReadOnlyMemory1 管道) 在 Azure.Core.Pipeline.HttpPipelinePolicy.ProcessNext(HttpMessage消息,ReadOnlyMemory1 管道)在 Azure.Core.Pipeline.HttpPipelineSynchronousPolicy.Process(HttpMessage 消息,ReadOnlyMemory1 管道)在 Azure.Core.Pipeline.HttpPipelinePolicy.ProcessNext(HttpMessage 消息,ReadOnlyMemory1 管道)在 Azure.Core.Pipeline.RetryPolicy。ProcessAsync(HttpMessage消息,ReadOnlyMemory`1管道,布尔异步)<---

--- 内部异常堆栈跟踪结束 --- System.Threading.Tasks.Task.WaitAllCore(Task[] tasks, Int32 millisecondsTimeout, CancellationToken cancelToken) at System.Threading.Tasks.Task.WaitAll(Task[] tasks)在 C:\Users\MeDev\source\repos\TestFormRecognizer\FormRecognizerTest\Program.cs:line 14 中的 FormRecognizerTest.Program.Main(String[] args) 中止

这里可能有什么问题?

我的环境:

  • 使用的包是 Azure.AI.FormRecognizer Version="3.1.1"。
  • 本地 PC 是 Windows 10;.NET Core 运行时:Microsoft.NETCore.App 5.0.8,SDK:5.0.302。
  • Azure VM 是 Ubuntu 20.04;.NET Core 运行时:Microsoft.NETCore.App 5.0.8。
4

0 回答 0