[Python] Document AI Classifier receives 404 Error

Discussão em 'Python' iniciado por Stack, Setembro 6, 2025.

  1. Stack

    Stack Membro Participativo

    1. I created a processor in google cloud(classifier).
    2. I trained it
    3. I deployed it
    4. I setup everything as it said in google cloud when you click on sample request: enter image description here
    5. I get this error:

    Traceback (most recent call last):
    File "c:\Users\Anwender\Desktop\floowy\Versicherung\code\test.py", line 95, in <module>
    process_document_sample(
    ~~~~~~~~~~~~~~~~~~~~~~~^
    project_id="466668368501",
    ^^^^^^^^^^^^^^^^^^^^^^^^^^
    ...<3 lines>...
    mime_type="application/pdf",
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    )
    ^
    File "c:\Users\Anwender\Desktop\floowy\Versicherung\code\test.py", line 83, in process_document_sample
    result = client.process_document(request=request)
    File "c:\Users\Anwender\AppData\Local\Programs\Python\Python313\Lib\site-packages\google\cloud\documentai_v1\services\document_processor_service\client.py", line 951, in process_document
    response = rpc(
    request,
    ...<2 lines>...
    metadata=metadata,
    )
    File "c:\Users\Anwender\AppData\Local\Programs\Python\Python313\Lib\site-packages\google\api_core\gapic_v1\method.py", line 131, in __call__
    return wrapped_func(*args, **kwargs)
    File "c:\Users\Anwender\AppData\Local\Programs\Python\Python313\Lib\site-packages\google\api_core\retry\retry_unary.py", line 294, in retry_wrapped_func
    return retry_target(
    target,
    ...<3 lines>...
    on_error=on_error,
    )
    File "c:\Users\Anwender\AppData\Local\Programs\Python\Python313\Lib\site-packages\google\api_core\retry\retry_unary.py", line 156, in retry_target
    next_sleep = _retry_error_helper(
    exc,
    ...<6 lines>...
    timeout,
    )
    File "c:\Users\Anwender\AppData\Local\Programs\Python\Python313\Lib\site-packages\google\api_core\retry\retry_base.py", line 214, in _retry_error_helper
    raise final_exc from source_exc
    File "c:\Users\Anwender\AppData\Local\Programs\Python\Python313\Lib\site-packages\google\api_core\retry\retry_unary.py", line 147, in retry_target
    result = target()
    File "c:\Users\Anwender\AppData\Local\Programs\Python\Python313\Lib\site-packages\google\api_core\timeout.py", line 130, in func_with_timeout
    return func(*args, **kwargs)
    File "c:\Users\Anwender\AppData\Local\Programs\Python\Python313\Lib\site-packages\google\api_core\grpc_helpers.py", line 78, in error_remapped_callable
    raise exceptions.from_grpc_error(exc) from exc
    google.api_core.exceptions.NotFound: 404 No such object: 466668368501-d418bbad5c2c13e5-training/d418bbad5c2c13e5/affa3098b893f053/training-data/15/b133e2f991bda0a0.json


    This is the code I used:

    # Copyright 2020 Google LLC
    #
    # Licensed under the Apache License, Version 2.0 (the "License");
    # you may not use this file except in compliance with the License.
    # You may obtain a copy of the License at
    #
    # http://www.apache.org/licenses/LICENSE-2.0
    #
    # Unless required by applicable law or agreed to in writing, software
    # distributed under the License is distributed on an "AS IS" BASIS,
    # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    # See the License for the specific language governing permissions and
    # limitations under the License.
    #

    # [START documentai_process_document]
    from typing import Optional

    from google.api_core.client_options import ClientOptions
    import os
    from google.cloud import documentai # type: ignore

    os.environ["GOOGLE_APPLICATION_CREDENTIALS"] = "creds/service_creds.json"

    project_id = "inspired-ether-458806-u7"
    location = "us" # Format is "us" or "eu"
    processor_id = "d418bbad5c2c13e5" # Create processor before running sample
    file_path = "/test_data/KFZ Audi A1.pdf" # The local file in your current working directory
    mime_type = "application/pdf" # Refer to https://cloud.google.com/document-ai/docs/file-types for supported file types
    field_mask = "text,entities,pages.pageNumber" # Optional. The fields to return in the Document object.
    processor_version_id = "affa3098b893f053" # Optional. Processor version to use


    def process_document_sample(
    project_id: str,
    location: str,
    processor_id: str,
    file_path: str,
    mime_type: str,
    field_mask: Optional[str] = None,
    processor_version_id: Optional[str] = None,
    ) -> None:
    # You must set the `api_endpoint` if you use a location other than "us".
    opts = ClientOptions(api_endpoint=f"{location}-documentai.googleapis.com")

    client = documentai.DocumentProcessorServiceClient(client_options=opts)

    if processor_version_id:
    # The full resource name of the processor version, e.g.:
    # `projects/{project_id}/locations/{location}/processors/{processor_id}/processorVersions/{processor_version_id}`
    name = client.processor_version_path(
    project_id, location, processor_id, processor_version_id
    )
    else:
    # The full resource name of the processor, e.g.:
    # `projects/{project_id}/locations/{location}/processors/{processor_id}`
    name = client.processor_path(project_id, location, processor_id)

    # Read the file into memory
    with open(file_path, "rb") as image:
    image_content = image.read()

    # Load binary data
    raw_document = documentai.RawDocument(content=image_content, mime_type=mime_type)

    # For more information: https://cloud.google.com/document-ai/docs/reference/rest/v1/ProcessOptions
    # Optional: Additional configurations for processing.
    process_options = documentai.ProcessOptions(
    # Process only specific pages
    individual_page_selector=documentai.ProcessOptions.IndividualPageSelector(
    pages=[1]
    )
    )

    # Configure the process request
    request = documentai.ProcessRequest(
    name=name,
    raw_document=raw_document,
    field_mask=field_mask,
    process_options=process_options,
    )

    result = client.process_document(request=request)

    # For a full list of `Document` object attributes, reference this page:
    # https://cloud.google.com/document-ai/docs/reference/rest/v1/Document
    document = result.document

    # Read the text recognition output from the processor
    print("The document contains the following text:")
    print(document.text)


    # [END documentai_process_document]
    process_document_sample(
    project_id="466668368501",
    location="us",
    processor_id="d418bbad5c2c13e5",
    file_path="./test_data/KFZ.pdf",
    mime_type="application/pdf",
    )


    I tried to get it to run but I got stuck every way I tried at this error.

    I set up the service account in google cloud as it said in the guide, but maybe there is some error, because I haven't found a single person online who had the same error as I have.

    Continue reading...

Compartilhe esta Página