I’m working with the Google Cloud Document AI API to process PDF files. I’m encountering the following error when trying to use the process_document method:
google.api_core.exceptions.FailedPrecondition: 400 Precondition check failed.
I made sure that the PDF is not corrupted and the size is correct, I tried to make a retry for this but still the same Exception.
# Read the file into memory
with open(pdf_file_path, "rb") as image:
image_content = image.read()
# Load binary data
raw_document = documentai.RawDocument(
content=image_content,
mime_type="application/pdf",
)
# Configure the process request
request = documentai.ProcessRequest(name=processor_name, raw_document=raw_document)
result = client.process_document(request=request)
document = result.document
return document.text
Full Error:
File "/workspace/main.py", line 185, in docAI_ocr
result = client.process_document(request=request)
File "/layers/google.python.pip/pip/lib/python3.9/site-packages/google/cloud/documentai_v1/services/document_processor_service/client.py", line 914, in process_document
response = rpc(
File "/layers/google.python.pip/pip/lib/python3.9/site-packages/google/api_core/gapic_v1/method.py", line 131, in __call__
return wrapped_func(*args, **kwargs)
File "/layers/google.python.pip/pip/lib/python3.9/site-packages/google/api_core/retry/retry_unary.py", line 293, in retry_wrapped_func
return retry_target(
File "/layers/google.python.pip/pip/lib/python3.9/site-packages/google/api_core/retry/retry_unary.py", line 153, in retry_target
_retry_error_helper(
File "/layers/google.python.pip/pip/lib/python3.9/site-packages/google/api_core/retry/retry_base.py", line 212, in _retry_error_helper
raise final_exc from source_exc
File "/layers/google.python.pip/pip/lib/python3.9/site-packages/google/api_core/retry/retry_unary.py", line 144, in retry_target
result = target()
File "/layers/google.python.pip/pip/lib/python3.9/site-packages/google/api_core/timeout.py", line 120, in func_with_timeout
return func(*args, **kwargs)
File "/layers/google.python.pip/pip/lib/python3.9/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.FailedPrecondition: 400 Precondition check failed.
Does anyone know how to solve this?
Recognized by Google Cloud Collective