首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >文档AI处理文档在处理GCS的文档时失败,参数无效。

文档AI处理文档在处理GCS的文档时失败,参数无效。
EN

Stack Overflow用户
提问于 2022-03-14 22:29:44
回答 2查看 510关注 0票数 1

我得到了一个非常类似于下面的错误,但我不在欧盟:core.exceptions.InvalidArgument: 400请求包含一个无效的参数

当我使用raw_document并处理本地pdf文件时,它工作得很好。但是,当我在GCS位置上指定一个pdf文件时,它会失败。

错误消息:

代码语言:javascript
复制
the processor name: projects/xxxxxxxxx/locations/us/processors/f7502cad4bccdd97
the form process request: name: "projects/xxxxxxxxx/locations/us/processors/f7502cad4bccdd97"
inline_document {
  uri: "gs://xxxx/temp/test1.pdf"
}

Traceback (most recent call last):
  File "C:\Python39\lib\site-packages\google\api_core\grpc_helpers.py", line 66, in error_remapped_callable
    return callable_(*args, **kwargs)
  File "C:\Python39\lib\site-packages\grpc\_channel.py", line 946, in __call__
    return _end_unary_response_blocking(state, call, False, None)
  File "C:\Python39\lib\site-packages\grpc\_channel.py", line 849, in _end_unary_response_blocking
    raise _InactiveRpcError(state)
grpc._channel._InactiveRpcError: <_InactiveRpcError of RPC that terminated with:
        status = StatusCode.INVALID_ARGUMENT
        details = "Request contains an invalid argument."
        debug_error_string = "{"created":"@1647296055.582000000","description":"Error received from peer ipv4:142.250.80.74:443","file":"src/core/lib/surface/call.cc","file_line":1070,"grpc_message":"Request contains an invalid argument.","grpc_status":3}"
>

代码:

代码语言:javascript
复制
   client = documentai.DocumentProcessorServiceClient(client_options=opts)

    # The full resource name of the processor, e.g.:
    # projects/project-id/locations/location/processor/processor-id
    # You must create new processors in the Cloud Console first
    name = f"projects/{project_id}/locations/{location}/processors/{processor_id}"
    print(f'the processor name: {name}')

    # document = {"uri": gcs_path, "mime_type": "application/pdf"}
    document = {"uri": gcs_path}
    inline_document = documentai.Document()
    inline_document.uri = gcs_path
    # inline_document.mime_type = "application/pdf"

    # Configure the process request
    # request = {"name": name, "inline_document": document}
    request = documentai.ProcessRequest(
        inline_document=inline_document,
        name=name
    )    

    print(f'the form process request: {request}')

    result = client.process_document(request=request)

我不认为我在存储桶上有权限问题,因为相同的设置对于同一桶上的文档分类过程很好。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2022-03-15 03:52:43

这对于文档AI来说是一个已知的问题,并且已经在这个问题跟踪器中报告过了。不幸的是,目前唯一的解决办法是:

  1. 下载您的文件,以字节形式读取该文件,并使用文件()。有关示例代码,请参见文档AI本地处理
  2. 使用文件(),因为默认情况下只接受来自GCS的文件。这是如果您不想做额外的步骤下载文件。
票数 1
EN

Stack Overflow用户

发布于 2022-08-23 03:11:29

这在5个月后仍然是一个问题,在接受的答案中没有提到的是(我可能错了,但在我看来)批处理只能将它们的结果输出到GCS,所以仍然需要额外的步骤从桶中下载一些东西(不管是选项1下的输入文档,还是选项2下的结果)。更重要的是,如果您不想获得结果,您将不得不在桶中进行清理,因此,在许多情况下,除了结果下载可能小于输入文件下载之外,选项2不会带来太大的优势。

我在Python函数中使用客户端库,并且受到这个问题的影响。我之所以实现选项1,是因为它看起来很简单,而且我一直在等待修复。我还考虑过使用工作流程客户端库来触发运行文档AI进程的工作流,或者调用Document,但这一切都不是最优的。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/71474905

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档