【发布时间】: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