【问题标题】:Google Document AI - Invalid argumentGoogle Document AI - 参数无效
【发布时间】:2022-02-09 02:36:03
【问题描述】:

我是 google Document AI 的新手,我尝试使用此代码但仍然有此响应。你知道我做错了什么吗? 我已经从 nuget Google.Cloud.DocumentAI.V1 安装

Status(StatusCode="InvalidArgument", Detail="Request contains an invalid argument.", DebugException="Grpc.Core.Internal.CoreErrorDetailException: {"created":"@1643889903.765000000","description":"收到错误from peer ipv4:142.250.186.42:443","file":"......\src\core\lib\surface\call.cc","file_line":1067,"grpc_message":"请求包含一个无效参数。","grpc_status":3}")

    public async void Start()
    {
        Environment.SetEnvironmentVariable("GOOGLE_APPLICATION_CREDENTIALS", @"path-to-json");

        try
        {
            //Generate a document
            string pdfFilePath = @"path-to-invoice-pdf";
            var bytes = File.ReadAllBytes(pdfFilePath);
            ByteString content = ByteString.CopyFrom(bytes);

            // Create client
            DocumentProcessorServiceClient documentProcessorServiceClient = await DocumentProcessorServiceClient.CreateAsync();
            // Initialize request argument(s)

            ProcessRequest request = new ProcessRequest
            {
                ProcessorName = ProcessorName.FromProjectLocationProcessor("ProjectID", "eu", "ProcessorID"),
                SkipHumanReview = false,
                RawDocument = new RawDocument
                {
                    MimeType = "application/pdf",
                    Content = content
                }
            };



            // Make the request
            ProcessResponse response = await documentProcessorServiceClient.ProcessDocumentAsync(request);

            Document docResponse = response.Document;

            Console.WriteLine(docResponse.Text);

        }
        catch (Exception ex)
        {
            Console.WriteLine(ex.Message);
        }


    }

【问题讨论】:

  • 当您的位置不是“我们”时,您必须设置参数“apiEndpoint”。参考这个类似的thread,如果有帮助,请告诉我?
  • 嗨,Vishal,是的,你说得对。在美国处理器中它工作正常,但对于欧盟是这个错误..但我找不到在哪里可以设置 apiEndpoint。
  • 嗨,维克多,我已经发布了答案。
  • 谢谢维沙尔

标签: c# google-api cloud-document-ai


【解决方案1】:

引用自doc

请注意,如果您希望在美国以外的地方使用DocumentProcessorServiceClient,则必须在构建客户端时指定端点。端点的格式为 {location}-documentai.googleapis.com,例如eu-documentai.googleapis.com。指定端点的最简单方法是使用DocumentProcessorServiceClientBuilder

DocumentProcessorServiceClient client = new DocumentProcessorServiceClientBuilder
{
    Endpoint = "eu-documentai.googleapis.com"
}.Build();

【讨论】:

    猜你喜欢
    • 2021-03-01
    • 2022-08-05
    • 2022-08-03
    • 2022-11-10
    • 2023-01-17
    • 2020-11-20
    • 2022-08-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多